OSSP CVS Repository

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

Check-in Number: 1003
Date: 2001-Sep-13 22:27:56 (local)
2001-Sep-13 20:27:56 (UTC)
User:rse
Branch:
Comment: implement sa_readfrom() and sa_writeto() functions
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ut_sa.c      1.9 -> 1.10     50 inserted, 13 deleted
ossp-pkg/l2/l2_ut_sa.h      1.5 -> 1.6     2 inserted, 2 deleted

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

--- l2_ut_sa.c   2001/09/13 20:13:08     1.9
+++ l2_ut_sa.c   2001/09/13 20:27:56     1.10
@@ -729,15 +729,39 @@
     return rv;
 }
 
-sa_rc_t sa_readfrom(sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t *addr)
+sa_rc_t sa_readfrom(sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t **raddr)
 {
     sa_rc_t rv;
+    union {
+        struct sockaddr_in sa4;
+#ifdef AF_INET6
+        struct sockaddr_in6 sa6;
+#endif
+    } sa_buf;
+    socklen_t sa_len;
+    size_t n;
+    fd_set fds;
 
-    if (sa->sSocket == -1)
-        if ((rv = sa_socket_init(sa, addr->saa_family, addr->saa_proto)) != SA_OK)
-            return rv;
-    /* FIXME: NOT YET IMPLEMENTED */
-    return SA_ERR_INT;
+    if (sa == NULL || buf == NULL || buflen == 0 || bufdone == NULL || raddr == NULL)
+        return SA_ERR_ARG;
+    if (sa->bTimeout) {
+        FD_ZERO(&fds);
+        FD_SET(sa->sSocket, &fds);
+        do {
+            n = select(sa->sSocket+1, &fds, NULL, NULL, &sa->tvTimeout);
+        } while (n == -1 && errno == EINTR);
+        if (n == 0) 
+            errno = ETIMEDOUT;
+        if (n <= 0)
+            return SA_ERR_SYS;
+    }
+    sa_len = sizeof(sa_buf);
+    if ((n = recvfrom(sa->sSocket, buf, buflen, 0, (struct sockaddr *)&sa_buf, &sa_len)) == -1)
+        return SA_ERR_SYS;
+    if ((rv = sa_s2a(raddr, (struct sockaddr *)&sa_buf, sa_len)) != SA_OK)
+        return rv;
+    *bufdone = n;
+    return SA_OK;
 }
 
 sa_rc_t sa_readline(sa_t *sa, char *cpBuf, size_t nBufReq, size_t *nBufRes)
@@ -814,15 +838,28 @@
     return SA_OK;
 }
 
-sa_rc_t sa_writeto(sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *addr)
+sa_rc_t sa_writeto(sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *raddr)
 {
-    sa_rc_t rv;
+    size_t n;
+    fd_set fds;
 
-    if (sa->sSocket == -1)
-        if ((rv = sa_socket_init(sa, addr->saa_family, addr->saa_proto)) != SA_OK)
-            return rv;
-    /* FIXME: NOT YET IMPLEMENTED */
-    return SA_ERR_INT;
+    if (sa == NULL || buf == NULL || buflen == 0 || bufdone == NULL || raddr == NULL)
+        return SA_ERR_ARG;
+    if (sa->bTimeout) {
+        FD_ZERO(&fds);
+        FD_SET(sa->sSocket, &fds);
+        do {
+            n = select(sa->sSocket+1, NULL, &fds, NULL, &sa->tvTimeout);
+        } while (n == -1 && errno == EINTR);
+        if (n == 0) 
+            errno = ETIMEDOUT;
+        if (n <= 0)
+            return SA_ERR_SYS;
+    }
+    if ((n = sendto(sa->sSocket, buf, buflen, 0, raddr->saa_buf, raddr->saa_len)) == -1)
+        return SA_ERR_SYS;
+    *bufdone = n;
+    return SA_OK;
 }
 
 sa_rc_t sa_printf(sa_t *sa, const char *cpFmt, ...)


ossp-pkg/l2/l2_ut_sa.h 1.5 -> 1.6

--- l2_ut_sa.h   2001/09/13 20:13:08     1.5
+++ l2_ut_sa.h   2001/09/13 20:27:56     1.6
@@ -69,10 +69,10 @@
 sa_rc_t sa_getlocal (sa_t *sa, sa_addr_t **laddr);
 
 sa_rc_t sa_read     (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
-sa_rc_t sa_readfrom (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t *addr);
+sa_rc_t sa_readfrom (sa_t *sa, char *buf, size_t buflen, size_t *bufdone, sa_addr_t **raddr);
 sa_rc_t sa_readline (sa_t *sa, char *buf, size_t buflen, size_t *bufdone);
 sa_rc_t sa_write    (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone);
-sa_rc_t sa_writeto  (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *addr);
+sa_rc_t sa_writeto  (sa_t *sa, const char *buf, size_t buflen, size_t *bufdone, sa_addr_t *raddr);
 sa_rc_t sa_printf   (sa_t *sa, const char *fmt, ...);
 sa_rc_t sa_flush    (sa_t *sa);
 sa_rc_t sa_shutdown (sa_t *sa, char *flags);

CVSTrac 2.0.1