rx-junk-writevinit-20021030
[openafs.git] / src / rx / rx_rdwr.c
index 2184f06..ea2cd60 100644 (file)
@@ -1,4 +1,4 @@
-/*
+ /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
  * 
@@ -7,43 +7,54 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
-#ifdef KERNEL
-#include "../afs/param.h"
+#include <afsconfig.h>
+#ifdef KERNEL
+#include "afs/param.h"
+#else
+#include <afs/param.h>
+#endif
+
+RCSID("$Header$");
+
+#ifdef KERNEL
 #ifndef UKERNEL
-#include "../h/types.h"
-#include "../h/time.h"
-#include "../h/stat.h"
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#include "afs/sysincludes.h"
+#else
+#include "h/types.h"
+#include "h/time.h"
+#include "h/stat.h"
 #ifdef AFS_OSF_ENV
 #include <net/net_globals.h>
 #endif /* AFS_OSF_ENV */
 #ifdef AFS_LINUX20_ENV
-#include "../h/socket.h"
+#include "h/socket.h"
 #endif
-#include "../netinet/in.h"
+#include "netinet/in.h"
 #if defined(AFS_SGI_ENV)
-#include "../afs/sysincludes.h"
+#include "afs/sysincludes.h"
 #endif
-#include "../afs/afs_args.h"
-#include "../afs/afs_osi.h"
+#endif
+#include "afs/afs_args.h"
+#include "afs/afs_osi.h"
 #if    (defined(AFS_AUX_ENV) || defined(AFS_AIX_ENV))
-#include "../h/systm.h"
+#include "h/systm.h"
 #endif
 #else /* !UKERNEL */
-#include "../afs/sysincludes.h"
+#include "afs/sysincludes.h"
 #endif /* !UKERNEL */
 #ifdef RXDEBUG
 #undef RXDEBUG     /* turn off debugging */
 #endif /* RXDEBUG */
-#include "../afsint/afsint.h"
-
-#include "../rx/rx_kmutex.h"
-#include "../rx/rx_kernel.h"
-#include "../rx/rx_clock.h"
-#include "../rx/rx_queue.h"
-#include "../rx/rx.h"
-#include "../rx/rx_globals.h"
-#include "../afs/lock.h"
-#include "../afsint/afsint.h"
+
+#include "rx_kmutex.h"
+#include "rx/rx_kernel.h"
+#include "rx/rx_clock.h"
+#include "rx/rx_queue.h"
+#include "rx/rx.h"
+#include "rx/rx_globals.h"
+#include "afs/lock.h"
+#include "afsint.h"
 #ifdef  AFS_ALPHA_ENV
 #undef kmem_alloc
 #undef kmem_free
@@ -52,7 +63,6 @@
 #undef register
 #endif  /* AFS_ALPHA_ENV */
 #else /* KERNEL */
-# include <afs/param.h>
 # include <sys/types.h>
 #ifndef AFS_NT40_ENV
 # include <sys/socket.h>
 # include <sys/stat.h>
 # include <sys/time.h>
 #endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 # include "rx_user.h"
 # include "rx_clock.h"
 # include "rx_queue.h"
 # include "rx.h"
 # include "rx_globals.h"
-# include "rx_internal.h"
 #endif /* KERNEL */
 
-
 #ifdef RX_LOCKS_DB
 /* rxdb_fileID is used to identify the lock location, along with line#. */
 static int rxdb_fileID = RXDB_FILE_RX_RDWR;
@@ -79,10 +97,8 @@ static int rxdb_fileID = RXDB_FILE_RX_RDWR;
  *
  * LOCKS USED -- called at netpri with rx global lock and call->lock held.
  */
-int rxi_ReadProc(call, buf, nbytes)
-    register struct rx_call *call;
-    register char *buf;
-    register int nbytes;
+int rxi_ReadProc(register struct rx_call *call, register char *buf, 
+       register int nbytes)
 {
     register struct rx_packet *cp = call->currentPacket;
     register struct rx_packet *rp;
@@ -125,7 +141,7 @@ int rxi_ReadProc(call, buf, nbytes)
                * work.  It may reduce the length of the packet by up
                * to conn->maxTrailerSize, to reflect the length of the
                * data + the header. */
-             if (error = RXS_CheckPacket(conn->securityObject, call, rp)) {
+             if ((error = RXS_CheckPacket(conn->securityObject, call, rp))) {
                /* Used to merely shut down the call, but now we 
                 * shut down the whole connection since this may 
                 * indicate an attempt to hijack it */
@@ -231,7 +247,7 @@ MTUXXX  doesn't there need to be an "else" here ???
        while (nbytes && cp) {
          t = MIN((int)call->curlen, nbytes);
          t = MIN(t, (int)call->nLeft);
-         bcopy (call->curpos, buf, t);
+         memcpy(buf, call->curpos, t);
          buf += t;
          nbytes -= t;
          call->curpos += t;
@@ -268,10 +284,7 @@ MTUXXX  doesn't there need to be an "else" here ???
     return requestCount;
 }
 
-int rx_ReadProc(call, buf, nbytes)
-  struct rx_call *call;
-  char *buf;
-  int nbytes;
+int rx_ReadProc(struct rx_call *call, char *buf, int nbytes)
 {
     int bytes;
     int tcurlen;
@@ -306,7 +319,7 @@ int rx_ReadProc(call, buf, nbytes)
     tnLeft = call->nLeft;
     if (!call->error && tcurlen > nbytes && tnLeft > nbytes) {
        tcurpos = call->curpos;
-       bcopy(tcurpos, buf, nbytes);
+       memcpy(buf, tcurpos, nbytes);
        call->curpos = tcurpos + nbytes;
        call->curlen = tcurlen - nbytes;
        call->nLeft = tnLeft - nbytes;
@@ -324,9 +337,7 @@ int rx_ReadProc(call, buf, nbytes)
 }
 
 /* Optimization for unmarshalling 32 bit integers */
-int rx_ReadProc32(call, value)
-  struct rx_call *call;
-  afs_int32 *value;
+int rx_ReadProc32(struct rx_call *call, afs_int32 *value)
 {
     int bytes;
     int tcurlen;
@@ -364,7 +375,7 @@ int rx_ReadProc32(call, value)
        if (!((long)tcurpos & (sizeof(afs_int32)-1))) {
            *value = *((afs_int32 *)(tcurpos));
        } else {
-           bcopy(tcurpos, (char *)value, sizeof(afs_int32));
+           memcpy((char *)value, tcurpos, sizeof(afs_int32));
        }
        call->curpos = tcurpos + sizeof(afs_int32);
        call->curlen = tcurlen - sizeof(afs_int32);
@@ -388,9 +399,8 @@ int rx_ReadProc32(call, value)
  * current iovec as possible. Does not block if it runs out
  * of packets to complete the iovec. Return true if an ack packet
  * was sent, otherwise return false */
-int rxi_FillReadVec(call, seq, serial, flags)
-  struct rx_call *call;
-  afs_uint32 seq, serial, flags;
+int rxi_FillReadVec(struct rx_call *call, afs_uint32 seq, 
+       afs_uint32 serial, afs_uint32 flags)
 {
     int didConsume = 0;
     int didHardAck = 0;
@@ -398,7 +408,7 @@ int rxi_FillReadVec(call, seq, serial, flags)
     struct rx_packet *rp;
     struct rx_packet *curp;
     struct iovec *call_iov;
-    struct iovec *cur_iov;
+    struct iovec *cur_iov = NULL;
 
     curp = call->currentPacket;
     if (curp) {
@@ -421,7 +431,7 @@ int rxi_FillReadVec(call, seq, serial, flags)
              * work.  It may reduce the length of the packet by up
              * to conn->maxTrailerSize, to reflect the length of the
              * data + the header. */
-           if (error = RXS_CheckPacket(conn->securityObject, call, rp)) {
+           if ((error = RXS_CheckPacket(conn->securityObject, call, rp))) {
              /* Used to merely shut down the call, but now we 
               * shut down the whole connection since this may 
               * indicate an attempt to hijack it */
@@ -545,12 +555,8 @@ int rxi_FillReadVec(call, seq, serial, flags)
  *
  * LOCKS USED -- called at netpri with rx global lock and call->lock held.
  */
-int rxi_ReadvProc(call, iov, nio, maxio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int *nio;
-    int maxio;
-    int nbytes;
+int rxi_ReadvProc(struct rx_call *call, struct iovec *iov, int *nio, 
+       int maxio, int nbytes)
 {
     struct rx_packet *rp; 
     struct rx_packet *nxp; /* Next packet pointer, for queue_Scan */
@@ -616,12 +622,8 @@ int rxi_ReadvProc(call, iov, nio, maxio, nbytes)
     return nbytes - call->iovNBytes;
 }
 
-int rx_ReadvProc(call, iov, nio, maxio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int *nio;
-    int maxio;
-    int nbytes;
+int rx_ReadvProc(struct rx_call *call, struct iovec *iov, 
+       int *nio, int maxio, int nbytes)
 {
     int bytes;
     SPLVAR;
@@ -640,10 +642,8 @@ int rx_ReadvProc(call, iov, nio, maxio, nbytes)
  *
  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
 
-int rxi_WriteProc(call, buf, nbytes)
-    register struct rx_call *call;
-    register char *buf;
-    register int nbytes;
+int rxi_WriteProc(register struct rx_call *call, register char *buf,   
+       register int nbytes)
 {
     struct rx_connection *conn = call->conn;
     register struct rx_packet *cp = call->currentPacket;
@@ -729,7 +729,7 @@ int rxi_WriteProc(call, buf, nbytes)
                }
 #endif /* RX_ENABLE_LOCKS */
            }
-           if (cp = rxi_AllocSendPacket(call, nbytes)) {
+           if ((cp = rxi_AllocSendPacket(call, nbytes))) {
                call->currentPacket = cp;
                call->nFree = cp->length;
                call->curvec = 1;   /* 0th vec is always header */
@@ -776,7 +776,7 @@ int rxi_WriteProc(call, buf, nbytes)
        
          t = MIN((int)call->curlen, nbytes);
          t = MIN((int)call->nFree, t);
-         bcopy (buf, call->curpos, t);
+         memcpy(call->curpos, buf, t);
          buf += t;
          nbytes -= t;
          call->curpos += t;
@@ -805,10 +805,7 @@ int rxi_WriteProc(call, buf, nbytes)
     return requestCount - nbytes;
 }
 
-int rx_WriteProc(call, buf, nbytes)
-  struct rx_call *call;
-  char *buf;
-  int nbytes;
+int rx_WriteProc(struct rx_call *call, char *buf, int nbytes)
 {
     int bytes;
     int tcurlen;
@@ -843,7 +840,7 @@ int rx_WriteProc(call, buf, nbytes)
     tnFree = (int)call->nFree;
     if (!call->error && tcurlen >= nbytes && tnFree >= nbytes) {
        tcurpos = call->curpos;
-       bcopy(buf, tcurpos, nbytes);
+       memcpy(tcurpos, buf, nbytes);
        call->curpos = tcurpos + nbytes;
        call->curlen = tcurlen - nbytes;
        call->nFree = tnFree - nbytes;
@@ -861,9 +858,7 @@ int rx_WriteProc(call, buf, nbytes)
 }
 
 /* Optimization for marshalling 32 bit arguments */
-int rx_WriteProc32(call, value)
-  register struct rx_call *call;
-  register afs_int32 *value;
+int rx_WriteProc32(register struct rx_call *call, register afs_int32 *value)
 {
     int bytes;
     int tcurlen;
@@ -901,7 +896,7 @@ int rx_WriteProc32(call, value)
        if (!((long)tcurpos & (sizeof(afs_int32)-1))) {
            *((afs_int32 *)(tcurpos)) = *value;
        } else {
-           bcopy((char *)value, tcurpos, sizeof(afs_int32));
+           memcpy(tcurpos, (char *)value, sizeof(afs_int32));
        }
        call->curpos = tcurpos + sizeof(afs_int32);
        call->curlen = tcurlen - sizeof(afs_int32);
@@ -926,12 +921,8 @@ int rx_WriteProc32(call, value)
  *
  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
 
-int rxi_WritevAlloc(call, iov, nio, maxio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int *nio;
-    int maxio;
-    int nbytes;
+int rxi_WritevAlloc(struct rx_call *call, struct iovec *iov, 
+       int *nio, int maxio, int nbytes)
 {
     struct rx_connection *conn = call->conn;
     struct rx_packet *cp = call->currentPacket;
@@ -1039,12 +1030,8 @@ int rxi_WritevAlloc(call, iov, nio, maxio, nbytes)
     return requestCount - nbytes;
 }
 
-int rx_WritevAlloc(call, iov, nio, maxio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int *nio;
-    int maxio;
-    int nbytes;
+int rx_WritevAlloc(struct rx_call *call, struct iovec *iov, int *nio, 
+       int maxio, int nbytes)
 {
     int bytes;
     SPLVAR;
@@ -1065,13 +1052,9 @@ int rx_WritevAlloc(call, iov, nio, maxio, nbytes)
  *
  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
 
-int rxi_WritevProc(call, iov, nio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int nio;
-    int nbytes;
+int rxi_WritevProc(struct rx_call *call, struct iovec *iov, 
+       int nio, int nbytes)
 {
-    struct rx_connection *conn = call->conn;
     struct rx_packet *cp = call->currentPacket;
     register struct rx_packet *tp; /* Temporary packet pointer */
     register struct rx_packet *nxp; /* Next packet pointer, for queue_Scan */
@@ -1119,8 +1102,6 @@ int rxi_WritevProc(call, iov, nio, nbytes)
     nextio = 0;
     queue_Init(&tmpq);
     do {
-       unsigned int t;
-
        if (call->nFree == 0 && cp) {
            clock_NewTime(); /* Bogus:  need new time package */
            /* The 0, below, specifies that it is not the last packet: 
@@ -1220,11 +1201,7 @@ int rxi_WritevProc(call, iov, nio, nbytes)
     return requestCount - nbytes;
 }
 
-int rx_WritevProc(call, iov, nio, nbytes)
-    struct rx_call *call;
-    struct iovec *iov;
-    int nio;
-    int nbytes;
+int rx_WritevProc(struct rx_call *call, struct iovec *iov, int nio, int nbytes)
 {
     int bytes;
     SPLVAR;
@@ -1241,8 +1218,7 @@ int rx_WritevProc(call, iov, nio, nbytes)
 
 /* Flush any buffered data to the stream, switch to read mode
  * (clients) or to EOF mode (servers) */
-void rxi_FlushWrite(call)
-    register struct rx_call *call;
+void rxi_FlushWrite(register struct rx_call *call)
 {
     register struct rx_packet *cp = call->currentPacket;
     register struct rx_packet *tp; /* Temporary packet pointer */
@@ -1305,8 +1281,7 @@ void rxi_FlushWrite(call)
 
 /* Flush any buffered data to the stream, switch to read mode
  * (clients) or to EOF mode (servers) */
-void rx_FlushWrite(call)
-  struct rx_call *call;
+void rx_FlushWrite(struct rx_call *call)
 {
     SPLVAR;
     NETPRI;