--- 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, ...)
|