| 235 return 0; |
235 return 0; |
| 236 } |
236 } |
| 237 |
237 |
| 238 if (h->state == GG_STATE_CONNECTING) { |
238 if (h->state == GG_STATE_CONNECTING) { |
| 239 int res = 0; |
239 int res = 0; |
| 240 unsigned int res_size = sizeof(res); |
240 socklen_t res_size = sizeof(res); |
| 241 |
241 |
| 242 if (h->async && (getsockopt(h->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { |
242 if (h->async && (getsockopt(h->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { |
| 243 gg_debug(GG_DEBUG_MISC, "=> http, async connection failed (errno=%d, %s)\n", (res) ? res : errno , strerror((res) ? res : errno)); |
243 gg_debug(GG_DEBUG_MISC, "=> http, async connection failed (errno=%d, %s)\n", (res) ? res : errno , strerror((res) ? res : errno)); |
| 244 close(h->fd); |
244 close(h->fd); |
| 245 h->fd = -1; |
245 h->fd = -1; |
| 254 |
254 |
| 255 h->state = GG_STATE_SENDING_QUERY; |
255 h->state = GG_STATE_SENDING_QUERY; |
| 256 } |
256 } |
| 257 |
257 |
| 258 if (h->state == GG_STATE_SENDING_QUERY) { |
258 if (h->state == GG_STATE_SENDING_QUERY) { |
| 259 int res; |
259 ssize_t res; |
| 260 |
260 |
| 261 if ((res = write(h->fd, h->query, strlen(h->query))) < 1) { |
261 if ((res = write(h->fd, h->query, strlen(h->query))) < 1) { |
| 262 gg_debug(GG_DEBUG_MISC, "=> http, write() failed (len=%d, res=%d, errno=%d)\n", strlen(h->query), res, errno); |
262 gg_debug(GG_DEBUG_MISC, "=> http, write() failed (len=%d, res=%d, errno=%d)\n", strlen(h->query), res, errno); |
| 263 gg_http_error(GG_ERROR_WRITING); |
263 gg_http_error(GG_ERROR_WRITING); |
| 264 } |
264 } |
| 265 |
265 |
| 266 if (res < strlen(h->query)) { |
266 if (res < 0 || (size_t)res < strlen(h->query)) { |
| 267 gg_debug(GG_DEBUG_MISC, "=> http, partial header sent (led=%d, sent=%d)\n", strlen(h->query), res); |
267 gg_debug(GG_DEBUG_MISC, "=> http, partial header sent (led=%d, sent=%d)\n", strlen(h->query), res); |
| 268 |
268 |
| 269 memmove(h->query, h->query + res, strlen(h->query) - res + 1); |
269 memmove(h->query, h->query + res, strlen(h->query) - res + 1); |
| 270 h->state = GG_STATE_SENDING_QUERY; |
270 h->state = GG_STATE_SENDING_QUERY; |
| 271 h->check = GG_CHECK_WRITE; |
271 h->check = GG_CHECK_WRITE; |