Gisle Vanem's fixes to use CURL_SOCKET_BAD more instead of -1 for sockets.

This commit is contained in:
Daniel Stenberg 2004-03-11 13:13:35 +00:00
parent 326e8b9fc1
commit e545e33d5f
7 changed files with 24 additions and 21 deletions

View File

@ -417,6 +417,7 @@ static bool verifyconnect(curl_socket_t sockfd)
/* This wasn't a successful connect */
return FALSE;
#else
(void)sockfd;
return TRUE;
#endif
}
@ -571,7 +572,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
*/
for (ai = remotehost->addr; ai; ai = ai->ai_next, aliasindex++) {
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sockfd < 0)
if (sockfd == CURL_SOCKET_BAD)
continue;
#else
/*
@ -681,7 +682,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
}
before = after;
}
if (sockfd < 0) {
if (sockfd == CURL_SOCKET_BAD) {
/* no good connect was made */
*sockconn = -1;
failf(data, "Connect failed");

View File

@ -166,7 +166,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
default:
/* we have received data here */
{
int s;
curl_socket_t s;
size_t size = sizeof(struct sockaddr_in);
struct sockaddr_in add;
@ -175,7 +175,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
sclose(sock); /* close the first socket */
if (-1 == s) {
if (CURL_SOCKET_BAD == s) {
/* DIE! */
failf(data, "Error accept()ing server connect");
return CURLE_FTP_PORT_FAILED;
@ -766,7 +766,7 @@ CURLcode Curl_ftp_done(struct connectdata *conn)
#endif
/* shut down the socket to inform the server we're done */
sclose(conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = -1;
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
if(!ftp->no_transfer) {
/* Let's see what the server says about the transfer we just performed,
@ -2379,10 +2379,10 @@ CURLcode Curl_ftp(struct connectdata *conn)
if(connected)
retcode = Curl_ftp_nextconnect(conn);
if(retcode && (conn->sock[SECONDARYSOCKET] >= 0)) {
if(retcode && (conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD)) {
/* Failure detected, close the second socket if it was created already */
sclose(conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = -1;
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
}
if(ftp->no_transfer)

View File

@ -486,7 +486,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
* possibly know if the connection is in a good shape or not now. */
easy->easy_conn->bits.close = TRUE;
if(-1 !=easy->easy_conn->sock[SECONDARYSOCKET]) {
if(CURL_SOCKET_BAD != easy->easy_conn->sock[SECONDARYSOCKET]) {
/* if we failed anywhere, we must clean up the secondary socket if
it was used */
sclose(easy->easy_conn->sock[SECONDARYSOCKET]);

View File

@ -1091,12 +1091,12 @@ CURLcode Curl_telnet(struct connectdata *conn)
HANDLE stdin_handle;
HANDLE objs[2];
DWORD waitret;
DWORD nread;
DWORD readfile_read;
#else
fd_set readfd;
fd_set keepfd;
ssize_t nread;
#endif
ssize_t nread;
bool keepon = TRUE;
char *buf = data->state.buffer;
struct TELNET *tn;
@ -1203,10 +1203,11 @@ CURLcode Curl_telnet(struct connectdata *conn)
char *buffer = buf;
if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
(LPDWORD)&nread, NULL)) {
&readfile_read, NULL)) {
keepon = FALSE;
break;
}
nread = readfile_read;
while(nread--) {
outbuf[0] = *buffer++;

View File

@ -63,6 +63,7 @@ static int gettimeofday(struct timeval *tp, void *nothing)
tp->tv_sec = Sec;
tp->tv_usec = Usec;
#endif /* WITHOUT_MM_LIB */
(void)nothing;
return 0;
}
#else /* WIN32 */

View File

@ -1312,13 +1312,13 @@ CURLcode Curl_readwrite_init(struct connectdata *conn)
if(conn->bits.getheader || !data->set.no_body) {
FD_ZERO (&k->readfd); /* clear it */
if(conn->sockfd != -1) {
if(conn->sockfd != CURL_SOCKET_BAD) {
FD_SET (conn->sockfd, &k->readfd); /* read socket */
k->keepon |= KEEP_READ;
}
FD_ZERO (&k->writefd); /* clear it */
if(conn->writesockfd != -1) {
if(conn->writesockfd != CURL_SOCKET_BAD) {
/* HTTP 1.1 magic:
Even if we require a 100-return code before uploading data, we might
@ -1408,7 +1408,7 @@ Transfer(struct connectdata *conn)
is different*/
Curl_readwrite_init(conn);
if((conn->sockfd == -1) && (conn->writesockfd == -1))
if((conn->sockfd == CURL_SOCKET_BAD) && (conn->writesockfd == CURL_SOCKET_BAD))
/* nothing to read, nothing to write, we're already OK! */
return CURLE_OK;
@ -1953,11 +1953,11 @@ CURLcode Curl_perform(struct SessionHandle *data)
* possibly know if the connection is in a good shape or not now. */
conn->bits.close = TRUE;
if(-1 != conn->sock[SECONDARYSOCKET]) {
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
/* if we failed anywhere, we must clean up the secondary socket if
it was used */
sclose(conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET]=-1;
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
}
}

View File

@ -1341,9 +1341,9 @@ CURLcode Curl_disconnect(struct connectdata *conn)
Curl_SSL_Close(conn);
/* close possibly still open sockets */
if(-1 != conn->sock[SECONDARYSOCKET])
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
sclose(conn->sock[SECONDARYSOCKET]);
if(-1 != conn->sock[FIRSTSOCKET])
if(CURL_SOCKET_BAD != conn->sock[FIRSTSOCKET])
sclose(conn->sock[FIRSTSOCKET]);
Curl_safefree(conn->user);
@ -2022,8 +2022,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* and we setup a few fields in case we end up actually using this struct */
conn->data = data; /* remember our daddy */
conn->sock[FIRSTSOCKET] = -1; /* no file descriptor */
conn->sock[SECONDARYSOCKET] = -1; /* no file descriptor */
conn->sock[FIRSTSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
conn->connectindex = -1; /* no index */
conn->bits.httpproxy = (data->change.proxy && *data->change.proxy &&
(data->set.proxytype == CURLPROXY_HTTP))?
@ -3164,7 +3164,7 @@ static CURLcode SetupConnection(struct connectdata *conn,
conn->bytecount = 0;
conn->headerbytecount = 0;
if(-1 == conn->sock[FIRSTSOCKET]) {
if(CURL_SOCKET_BAD == conn->sock[FIRSTSOCKET]) {
bool connected;
/* Connect only if not already connected! */