| 2340 | */ |
| 2341 | |
| 2342 | int /* O - 0 on success, non-zero on failure */ |
| 2343 | httpReconnect2(http_t *http, /* I - HTTP connection */ |
| 2344 | int msec, /* I - Timeout in milliseconds */ |
| 2345 | int *cancel) /* I - Pointer to "cancel" variable */ |
| 2346 | { |
| 2347 | http_addrlist_t *addr; /* Connected address */ |
| 2348 | #ifdef DEBUG |
| 2349 | http_addrlist_t *current; /* Current address */ |
| 2350 | char temp[256]; /* Temporary address string */ |
| 2351 | #endif /* DEBUG */ |
| 2352 | |
| 2353 | |
| 2354 | DEBUG_printf(("httpReconnect2(http=%p, msec=%d, cancel=%p)", (void *)http, msec, (void *)cancel)); |
| 2355 | |
| 2356 | if (!http) |
| 2357 | { |
| 2358 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 2359 | return (-1); |
| 2360 | } |
| 2361 | |
| 2362 | #ifdef HAVE_TLS |
| 2363 | if (http->tls) |
| 2364 | { |
| 2365 | DEBUG_puts("2httpReconnect2: Shutting down SSL/TLS..."); |
| 2366 | _httpTLSStop(http); |
| 2367 | } |
| 2368 | #endif /* HAVE_TLS */ |
| 2369 | |
| 2370 | /* |
| 2371 | * Close any previously open socket... |
| 2372 | */ |
| 2373 | |
| 2374 | if (http->fd >= 0) |
| 2375 | { |
| 2376 | DEBUG_printf(("2httpReconnect2: Closing socket %d...", http->fd)); |
| 2377 | |
| 2378 | httpAddrClose(NULL, http->fd); |
| 2379 | |
| 2380 | http->fd = -1; |
| 2381 | } |
| 2382 | |
| 2383 | /* |
| 2384 | * Reset all state (except fields, which may be reused)... |
| 2385 | */ |
| 2386 | |
| 2387 | http->state = HTTP_STATE_WAITING; |
| 2388 | http->version = HTTP_VERSION_1_1; |
| 2389 | http->keep_alive = HTTP_KEEPALIVE_OFF; |
| 2390 | memset(&http->_hostaddr, 0, sizeof(http->_hostaddr)); |
| 2391 | http->data_encoding = HTTP_ENCODING_FIELDS; |
| 2392 | http->_data_remaining = 0; |
| 2393 | http->used = 0; |
| 2394 | http->data_remaining = 0; |
| 2395 | http->hostaddr = NULL; |
| 2396 | http->wused = 0; |
| 2397 | |
| 2398 | /* |
| 2399 | * Connect to the server... |