Forward port SOCKSENDBUF, SOCKRECVBUF features from 2.10.11.
[ircu2.10.12-pk.git] / ircd / os_solaris.c
index b7549880d0d966e16af474aa666fc9f52a7a438c..9452c0c77133545d9438aaedb8579c2d2ea6f3c3 100644 (file)
  * $Id$
  *
  */
+#include "config.h"
+
 #include "ircd_osdep.h"
+#include "msgq.h"
 
 #include <assert.h>
 #include <errno.h>
+#include <limits.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>
+#include <stropts.h>
 #include <sys/filio.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 #include <unistd.h>
 
 /*
@@ -91,6 +97,7 @@ int os_get_sockerr(int fd)
   int err = 0;
   int len = sizeof(err);
   getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*) &err, &len);
+  return err;
 }
 
 /*
@@ -118,13 +125,20 @@ int os_set_reuseaddr(int fd)
                           (const char*) &opt, sizeof(opt)));
 }
 
-int os_set_sockbufs(int fd, unsigned int size)
+int os_set_sockbufs(int fd, unsigned int ssize, unsigned int rsize)
 {
-  unsigned int opt = size;
+  unsigned int sopt = ssize;
+  unsigned int ropt = rsize;
   return (0 == setsockopt(fd, SOL_SOCKET, SO_RCVBUF, 
-                          (const char*) &opt, sizeof(opt)) &&
+                          (const char*) &ropt, sizeof(ropt)) &&
           0 == setsockopt(fd, SOL_SOCKET, SO_SNDBUF, 
-                          (const char*) &opt, sizeof(opt)));
+                          (const char*) &sopt, sizeof(sopt)));
+}
+
+int os_set_tos(int fd,int tos)
+{
+  unsigned int opt = tos;
+  return (0 == setsockopt(fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)));
 }
 
 int os_disable_options(int fd)
@@ -213,13 +227,39 @@ IOResult os_send_nonb(int fd, const char* buf, unsigned int length,
   return IO_FAILURE;
 }
 
-int os_connect_nonb(int fd, const struct sockaddr_in* sin)
+IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in,
+                      unsigned int* count_out)
 {
-  if (connect(fd, (struct sockaddr*) sin, sizeof(struct sockaddr_in))) {
-    if (errno != EINPROGRESS)
-      return 0;
+  int res;
+  int count;
+  struct iovec iov[IOV_MAX];
+
+  assert(0 != buf);
+  assert(0 != count_in);
+  assert(0 != count_out);
+
+  *count_in = 0;
+  *count_out = 0;
+  errno = 0;
+
+  count = msgq_mapiov(buf, iov, IOV_MAX, count_in);
+
+  if (-1 < (res = writev(fd, iov, count))) {
+    *count_out = (unsigned) res;
+    return IO_SUCCESS;
   }
-  return 1;
+  else if (EAGAIN == errno || ENOBUFS == errno ||
+          ENOMEM == errno || ENOSR == errno)
+    return IO_BLOCKED;
+
+  return IO_FAILURE;
+}
+
+IOResult os_connect_nonb(int fd, const struct sockaddr_in* sin)
+{
+  if (connect(fd, (struct sockaddr*) sin, sizeof(struct sockaddr_in)))
+    return (errno == EINPROGRESS) ? IO_BLOCKED : IO_FAILURE;
+  return IO_SUCCESS;
 }
       
 int os_get_sockname(int fd, struct sockaddr_in* sin_out)