another win32 portability fix: make sysread() and syswrite()
Gurusamy Sarathy [Sat, 21 Nov 1998 08:45:06 +0000 (08:45 +0000)]
work on sockets

p4raw-id: //depot/perl@2255

pp_sys.c
win32/win32.h

index 8fa38f2..b3de2f8 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1422,7 +1422,17 @@ PP(pp_sysread)
        Zero(buffer+bufsize, offset-bufsize, char);
     }
     if (PL_op->op_type == OP_SYSREAD) {
-       length = PerlLIO_read(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
+#ifdef PERL_SOCK_SYSREAD_IS_RECV
+       if (IoTYPE(io) == 's') {
+           length = PerlSock_recv(PerlIO_fileno(IoIFP(io)),
+                                  buffer+offset, length, 0);
+       }
+       else
+#endif
+       {
+           length = PerlLIO_read(PerlIO_fileno(IoIFP(io)),
+                                 buffer+offset, length);
+       }
     }
     else
 #ifdef HAS_SOCKET__bad_code_maybe
@@ -1534,7 +1544,17 @@ PP(pp_send)
            offset = 0;
        if (length > blen - offset)
            length = blen - offset;
-       length = PerlLIO_write(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
+#ifdef PERL_SOCK_SYSWRITE_IS_SEND
+       if (IoTYPE(io) == 's') {
+           length = PerlSock_send(PerlIO_fileno(IoIFP(io)),
+                                  buffer+offset, length, 0);
+       }
+       else
+#endif
+       {
+           length = PerlLIO_write(PerlIO_fileno(IoIFP(io)),
+                                  buffer+offset, length);
+       }
     }
 #ifdef HAS_SOCKET
     else if (SP > MARK) {
index b52ef4e..fef3cbc 100644 (file)
@@ -104,6 +104,11 @@ struct tms {
  * real filehandles. XXX Should always be defined (the other version is untested) */
 #define USE_SOCKETS_AS_HANDLES
 
+/* read() and write() aren't transparent for socket handles */
+#define PERL_SOCK_SYSREAD_IS_RECV
+#define PERL_SOCK_SYSWRITE_IS_SEND
+
+
 /* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
  * to read the environment, bypassing the runtime's (usually broken)
  * facilities for accessing the same.  See note in util.c/my_setenv(). */