OSSP CVS Repository

ossp - Check-in [1008]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1008
Date: 2001-Sep-14 12:22:37 (local)
2001-Sep-14 10:22:37 (UTC)
User:rse
Branch:
Comment: Allow the result parameter to be NULL if the caller wants to ignore the number written/read bytes.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ut_sa.c      1.10 -> 1.11     27 inserted, 16 deleted

ossp-pkg/l2/l2_ut_sa.c 1.10 -> 1.11

--- l2_ut_sa.c   2001/09/13 20:27:56     1.10
+++ l2_ut_sa.c   2001/09/14 10:22:37     1.11
@@ -679,22 +679,23 @@
 {
     int n;
     int rv;
+    size_t res;
 
-    if (sa == NULL)
+    if (sa == NULL || cpBuf == NULL || nBufReq == 0)
         return 0;
     
     /* flush write buffer */
     if (sa->nWriteLen > 0)
         sa_flush(sa);
     rv = SA_OK;
-    *nBufRes = 0;
+    res = 0;
     while (1) {
         if (nBufReq <= sa->nReadLen) {
             /* buffer holds enough data, so use this */
             memmove(cpBuf, sa->cpReadBuf, nBufReq);
             memmove(sa->cpReadBuf, sa->cpReadBuf+nBufReq, sa->nReadLen-nBufReq);
             sa->nReadLen -= nBufReq;
-            *nBufRes += nBufReq;
+            res += nBufReq;
         }
         else {
             if (sa->nReadLen > 0) {
@@ -702,14 +703,14 @@
                 memmove(cpBuf, sa->cpReadBuf, sa->nReadLen);
                 nBufReq -= sa->nReadLen;
                 cpBuf   += sa->nReadLen;
-                *nBufRes += sa->nReadLen;
+                res     += sa->nReadLen;
                 sa->nReadLen = 0;
             }
             if (nBufReq >= sa->nReadSize) {
                 /* buffer is too small at all, so read directly */
                 n = sa_read_raw(sa, cpBuf, nBufReq);
                 if (n > 0)
-                    *nBufRes += n;
+                    res += n;
                 else if (n <= 0)
                     rv = SA_ERR_SYS;
             }
@@ -726,6 +727,8 @@
         }
         break;
     }
+    if (nBufRes != NULL)
+        *nBufRes = res;
     return rv;
 }
 
@@ -742,7 +745,7 @@
     size_t n;
     fd_set fds;
 
-    if (sa == NULL || buf == NULL || buflen == 0 || bufdone == NULL || raddr == NULL)
+    if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
         return SA_ERR_ARG;
     if (sa->bTimeout) {
         FD_ZERO(&fds);
@@ -760,7 +763,8 @@
         return SA_ERR_SYS;
     if ((rv = sa_s2a(raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
         return rv;
-    *bufdone = n;
+    if (bufdone != NULL)
+        *bufdone = n;
     return SA_OK;
 }
 
@@ -768,19 +772,22 @@
 {
     char c;
     size_t n;
+    size_t res;
 
     if (sa == NULL)
         return SA_ERR_ARG;
-    *nBufRes = 0;
-    while ((*nBufRes) < (nBufReq-1)) {
+    res = 0;
+    while (res < (nBufReq-1)) {
         sa_read(sa, &c, 1, &n);
         if (n <= 0)
             break;
-        cpBuf[(*nBufRes)++] = c;
+        cpBuf[res++] = c;
         if (c == '\n')
             break;
     }
-    cpBuf[(*nBufRes)] = '\0';
+    cpBuf[res] = '\0';
+    if (nBufRes != NULL)
+        *nBufRes = res;
     return SA_OK;
 }
 
@@ -809,6 +816,7 @@
 sa_rc_t sa_write(sa_t *sa, const char *cpBuf, size_t nBufReq, size_t *nBufRes)
 {
     size_t n;
+    size_t res;
 
     if (sa == NULL)
         return SA_ERR_ARG;
@@ -817,24 +825,26 @@
         /* not enough space in buffer, so flush buffer */
         sa_flush(sa);
     }
+    res = 0;
     if (nBufReq >= sa->nWriteSize) {
         /* buffer too small at all, so write immediately */
-        *nBufRes = 0;
         while (nBufReq > 0) {
             n = sa_write_raw(sa, cpBuf, nBufReq);
             if (n <= 0)
                 break;
             nBufReq  -= n;
             cpBuf    += n;
-            *nBufRes += n;
+            res      += n;
         }
     }
     else {
         /* (again) enough sprace in buffer, so store data */
         memmove(sa->cpWriteBuf+sa->nWriteLen, cpBuf, nBufReq);
         sa->nWriteLen += nBufReq;
-        *nBufRes = nBufReq;
+        res = nBufReq;
     }
+    if (nBufRes != NULL)
+        *nBufRes = res;
     return SA_OK;
 }
 
@@ -843,7 +853,7 @@
     size_t n;
     fd_set fds;
 
-    if (sa == NULL || buf == NULL || buflen == 0 || bufdone == NULL || raddr == NULL)
+    if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
         return SA_ERR_ARG;
     if (sa->bTimeout) {
         FD_ZERO(&fds);
@@ -858,7 +868,8 @@
     }
     if ((n = sendto(sa->sSocket, buf, buflen, 0, raddr->saa_buf, raddr->saa_len)) == -1)
         return SA_ERR_SYS;
-    *bufdone = n;
+    if (bufdone != NULL)
+        *bufdone = n;
     return SA_OK;
 }
 

CVSTrac 2.0.1