]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Use platform's native types for recv() and send() arguments.
authorYang Tse <yangsita@gmail.com>
Wed, 12 Jul 2006 05:19:00 +0000 (05:19 +0000)
committerYang Tse <yangsita@gmail.com>
Wed, 12 Jul 2006 05:19:00 +0000 (05:19 +0000)
lib/sendf.c
lib/setup.h
lib/telnet.c
tests/server/sockfilt.c
tests/server/sws.c

index d248c189a0a9de3536ebbc63b26dd55d8b6f57e6..d598197bdc6711b8e47eb7a68f433b1a96a32fa6 100644 (file)
@@ -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();
index 57ac87d5b6c4ec9962b520d9d8622fbe9c5aee2b..cf7216ba0b5c3f0b5998725407db76d7fe999bba 100644 (file)
@@ -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 <sys/ioctl.h>
 #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
index a609cd09231718c4d6fa2592809730ef66a422ad..0b57f770697a1b83f229a0beb3a6a8d0613ae69f 100644 (file)
@@ -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;
   }
index eec0cd39f172e89455f887aa8dd842b6aa6ccd39..636132615594ef1faac13305998fde1c0e3e1f16 100644 (file)
@@ -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! */
index 95429dfcd4ef2e46cff42f96552e376f2f1429a3..3eff97d45af8eacd771d0bd408ede0337fac7cf7 100644 (file)
@@ -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;
       }