diff --git a/lib/sendf.c b/lib/sendf.c index d248c189a..d598197bd 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -332,7 +332,7 @@ CURLcode Curl_write(struct connectdata *conn, /* only TRUE if krb4 enabled */ bytes_written = Curl_sec_write(conn, sockfd, mem, len); else - bytes_written = (ssize_t)swrite(sockfd, mem, len); + bytes_written = swrite(sockfd, mem, len); if(-1 == bytes_written) { int err = Curl_sockerrno(); diff --git a/lib/setup.h b/lib/setup.h index 57ac87d5b..cf7216ba0 100644 --- a/lib/setup.h +++ b/lib/setup.h @@ -214,6 +214,65 @@ typedef unsigned char bool; #define struct_stat struct stat #endif /* Win32 with large file support */ +/* + * The definitions for the return type and arguments types + * of functions recv() and send() belong and come from the + * configuration file. Do not define them in any other place. + * + * HAVE_RECV is defined if you have a function named recv() + * which is used to read incoming data from sockets. If your + * function has another name then don't define HAVE_RECV. + * + * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, + * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also + * be defined. + * + * HAVE_SEND is defined if you have a function named send() + * which is used to write outgoing data on a connected socket. + * If yours has another name then don't define HAVE_SEND. + * + * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, + * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and + * SEND_TYPE_RETV must also be defined. + */ + +#ifdef HAVE_RECV +#if !defined(RECV_TYPE_ARG1) || \ + !defined(RECV_TYPE_ARG2) || \ + !defined(RECV_TYPE_ARG3) || \ + !defined(RECV_TYPE_ARG4) || \ + !defined(RECV_TYPE_RETV) + /* */ + Error: Missing definition of return and arguments types of recv(). + /* */ +#else +#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)x, (RECV_TYPE_ARG2)y, (RECV_TYPE_ARG3)z, (RECV_TYPE_ARG4)SEND_4TH_ARG) +#endif +#else /* HAVE_RECV */ +#ifdef DJGPP +#define sread(x,y,z) (ssize_t)read_s((int)x, (char *)y, (int)z) +#endif +#endif /* HAVE_RECV */ + +#ifdef HAVE_SEND +#if !defined(SEND_TYPE_ARG1) || \ + !defined(SEND_QUAL_ARG2) || \ + !defined(SEND_TYPE_ARG2) || \ + !defined(SEND_TYPE_ARG3) || \ + !defined(SEND_TYPE_ARG4) || \ + !defined(SEND_TYPE_RETV) + /* */ + Error: Missing definition of return and arguments types of send(). + /* */ +#else +#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)x, (SEND_TYPE_ARG2)y, (SEND_TYPE_ARG3)z, (SEND_TYPE_ARG4)SEND_4TH_ARG) +#endif +#else /* HAVE_SEND */ +#ifdef DJGPP +#define swrite(x,y,z) (ssize_t)write_s((int)x, (char *)y, (int)z) +#endif +#endif /* HAVE_SEND */ + /* Below we define four functions. They should 1. close a socket @@ -229,16 +288,10 @@ typedef unsigned char bool; #if !defined(__GNUC__) || defined(__MINGW32__) #define sclose(x) closesocket(x) -/* Since Windows doesn't have/use the POSIX prototype for send() and recv(), - we typecast the third argument in the macros to avoid compiler warnings. */ -#define sread(x,y,z) recv(x,y,(int)(z), SEND_4TH_ARG) -#define swrite(x,y,z) (size_t)send(x,y, (int)(z), SEND_4TH_ARG) #undef HAVE_ALARM #else /* gcc-for-win is still good :) */ #define sclose(x) close(x) -#define sread(x,y,z) recv(x,y,z, SEND_4TH_ARG) -#define swrite(x,y,z) send(x,y,z, SEND_4TH_ARG) #define HAVE_ALARM #endif /* !GNU or mingw */ @@ -250,8 +303,6 @@ typedef unsigned char bool; #ifdef DJGPP #include #define sclose(x) close_s(x) -#define sread(x,y,z) read_s(x,y,z) -#define swrite(x,y,z) write_s(x,y,z) #define select(n,r,w,x,t) select_s(n,r,w,x,t) #define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z)) #define IOCTL_3_ARGS @@ -264,12 +315,8 @@ typedef unsigned char bool; #ifdef __BEOS__ #define sclose(x) closesocket(x) -#define sread(x,y,z) (ssize_t)recv(x,y,z, SEND_4TH_ARG) -#define swrite(x,y,z) (ssize_t)send(x,y,z, SEND_4TH_ARG) #else /* __BEOS__ */ #define sclose(x) close(x) -#define sread(x,y,z) recv(x,y,z, SEND_4TH_ARG) -#define swrite(x,y,z) send(x,y,z, SEND_4TH_ARG) #endif /* __BEOS__ */ #define HAVE_ALARM diff --git a/lib/telnet.c b/lib/telnet.c index a609cd092..0b57f7706 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -289,12 +289,13 @@ static void printoption(struct SessionHandle *data, static void send_negotiation(struct connectdata *conn, int cmd, int option) { unsigned char buf[3]; + ssize_t bytes_written; buf[0] = CURL_IAC; buf[1] = cmd; buf[2] = option; - (void)swrite(conn->sock[FIRSTSOCKET], (char *)buf, 3); + bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3); printoption(conn->data, "SENT", cmd, option); } @@ -843,6 +844,7 @@ static void suboption(struct connectdata *conn) { struct curl_slist *v; unsigned char temp[2048]; + ssize_t bytes_written; size_t len; size_t tmplen; char varname[128]; @@ -857,7 +859,7 @@ static void suboption(struct connectdata *conn) snprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE, CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE); - (void)swrite(conn->sock[FIRSTSOCKET], (char *)temp, len); + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); printsub(data, '>', &temp[2], len-2); break; case CURL_TELOPT_XDISPLOC: @@ -865,7 +867,7 @@ static void suboption(struct connectdata *conn) snprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC, CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE); - (void)swrite(conn->sock[FIRSTSOCKET], (char *)temp, len); + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); printsub(data, '>', &temp[2], len-2); break; case CURL_TELOPT_NEW_ENVIRON: @@ -888,7 +890,7 @@ static void suboption(struct connectdata *conn) snprintf((char *)&temp[len], sizeof(temp) - len, "%c%c", CURL_IAC, CURL_SE); len += 2; - (void)swrite(conn->sock[FIRSTSOCKET], (char *)temp, len); + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); printsub(data, '>', &temp[2], len-2); break; } diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index eec0cd39f..636132615 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -173,6 +173,7 @@ static int juggle(curl_socket_t *sockfdp, unsigned char buffer[256]; /* FIX: bigger buffer */ char data[256]; curl_socket_t sockfd; + ssize_t bytes_written; timeout.tv_sec = 120; timeout.tv_usec = 0; @@ -301,7 +302,7 @@ static int juggle(curl_socket_t *sockfdp, } else /* send away on the socket */ - swrite(sockfd, buffer, len); + bytes_written = swrite(sockfd, buffer, len); } else if(!memcmp("DISC", buffer, 4)) { /* disconnect! */ diff --git a/tests/server/sws.c b/tests/server/sws.c index 95429dfcd..3eff97d45 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -493,7 +493,7 @@ static int get_request(int sock, struct httprequest *req) /* returns -1 on failure */ static int send_doc(int sock, struct httprequest *req) { - int written; + ssize_t written; size_t count; const char *buffer; char *ptr; @@ -519,7 +519,7 @@ static int send_doc(int sock, struct httprequest *req) count = strlen(STREAMTHIS); while(1) { written = swrite(sock, STREAMTHIS, count); - if(written != (int)count) { + if(written != count) { logmsg("Stopped streaming"); break; }