Revision ddcccc93 input-chunkstream.c

View differences:

input-chunkstream.c
119 119

  
120 120
  c->data = NULL;
121 121
  ret = recv(s->fd, recvbuf + pos, BUFSIZE - pos, 0);
122
  if (ret <= 0 && pos < sizeof(size)) {
122
  if (ret < 0) {
123 123
#ifndef _WIN32
124
    if (ret == -1 &&  (errno == EAGAIN || errno == EWOULDBLOCK)) {
124
    if (errno != EAGAIN && errno != EWOULDBLOCK) {
125 125
#else
126
    if (ret == -1 &&  WSAGetLastError() == WSAEWOULDBLOCK) {
126
    if (WSAGetLastError() != WSAEWOULDBLOCK) {
127 127
#endif
128
      return 999999;
129
    } else {
130 128
      perror("chunkstream connection error");
131 129
      exit(EXIT_FAILURE);
132 130
    }
133 131
  } else {
134 132
    pos += ret;
135 133
  }
134

  
136 135
  if ( pos < sizeof(size)) {
137
    return 999999;
136
    return INT_MAX;
138 137
  }
139 138

  
140 139
  size = ntohl(*(uint32_t*)recvbuf);
......
142 141
    ret = decodeChunk(c, recvbuf + sizeof(size), size);
143 142
    if (ret < 0) {
144 143
      printf("Error decoding chunk!\n");
145
      return 999999;
144
      return INT_MAX;
146 145
    }
147 146

  
148 147
    // remove attributes //TODO: verify whether this is the right place to do this
......
155 154
    pos -= sizeof(size) + size;
156 155
    memmove(recvbuf, recvbuf + sizeof(size) + size, pos);
157 156
  }
158
  return 999999;
157

  
158
  //check if there are other chunks in the buffer
159
  if ( pos >= sizeof(size)) {
160
    size = ntohl(*(uint32_t*)recvbuf);
161
    if (pos >= sizeof(size) + size) {
162
      return 0;
163
    }
164
  }
165

  
166
  return INT_MAX;
159 167
}

Also available in: Unified diff