summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2005-06-06 04:07:10 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:57:06 -0500
commit06ae1e805e45fa381739a64ef79fa99b25fa025c (patch)
tree4a47aed0bef1263d26bb4d0d535e0e248c3297dd /source3
parentbf484a8f8e7d3c925a4916fdbb91c2843532ec63 (diff)
downloadsamba-06ae1e805e45fa381739a64ef79fa99b25fa025c.tar.gz
samba-06ae1e805e45fa381739a64ef79fa99b25fa025c.tar.bz2
samba-06ae1e805e45fa381739a64ef79fa99b25fa025c.zip
r7318: Unify HEAD and 3.0 socket functions. Add HEAD functions here #ifdef'ed out.
Correct branch this time ! Jeremy. (This used to be commit 052b4f8e2849b4897176e64cc29b6a5f686d946e)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_sock.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 20dbdf8054..6107e5abed 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -241,6 +241,99 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len)
return(ret);
}
+#if 0
+
+Socket routines from HEAD - maybe re-enable in future. JRA.
+
+/****************************************************************************
+ Work out if we've timed out.
+****************************************************************************/
+
+static BOOL timeout_until(struct timeval *timeout, const struct timeval *endtime)
+{
+ struct timeval now;
+ SMB_BIG_INT t_dif;
+
+ GetTimeOfDay(&now);
+
+ t_dif = usec_time_diff(endtime, &now);
+ if (t_dif <= 0) {
+ return False;
+ }
+
+ timeout->tv_sec = (t_dif / (SMB_BIG_INT)1000000);
+ timeout->tv_usec = (t_dif % (SMB_BIG_INT)1000000);
+ return True;
+}
+
+/****************************************************************************
+ Read data from the client, reading exactly N bytes, or until endtime timeout.
+ Use with a non-blocking socket if endtime != NULL.
+****************************************************************************/
+
+ssize_t read_data_until(int fd,char *buffer,size_t N, const struct timeval *endtime)
+{
+ ssize_t ret;
+ size_t total=0;
+
+ smb_read_error = 0;
+
+ while (total < N) {
+
+ if (endtime != NULL) {
+ fd_set r_fds;
+ struct timeval timeout;
+ int selrtn;
+
+ if (!timeout_until(&timeout, endtime)) {
+ DEBUG(10,("read_data_until: read timed out\n"));
+ smb_read_error = READ_TIMEOUT;
+ return -1;
+ }
+
+ FD_ZERO(&r_fds);
+ FD_SET(fd, &r_fds);
+
+ /* Select but ignore EINTR. */
+ selrtn = sys_select_intr(fd+1, &r_fds, NULL, NULL, &timeout);
+ if (selrtn == -1) {
+ /* something is wrong. Maybe the socket is dead? */
+ DEBUG(0,("read_data_until: select error = %s.\n", strerror(errno) ));
+ smb_read_error = READ_ERROR;
+ return -1;
+ }
+
+ /* Did we timeout ? */
+ if (selrtn == 0) {
+ DEBUG(10,("read_data_until: select timed out.\n"));
+ smb_read_error = READ_TIMEOUT;
+ return -1;
+ }
+ }
+
+ ret = sys_read(fd,buffer + total,N - total);
+
+ if (ret == 0) {
+ DEBUG(10,("read_data_until: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) ));
+ smb_read_error = READ_EOF;
+ return 0;
+ }
+
+ if (ret == -1) {
+ if (errno == EAGAIN) {
+ /* Non-blocking socket with no data available. Try select again. */
+ continue;
+ }
+ DEBUG(0,("read_data_until: read failure for %d. Error = %s\n", (int)(N - total), strerror(errno) ));
+ smb_read_error = READ_ERROR;
+ return -1;
+ }
+ total += ret;
+ }
+ return (ssize_t)total;
+}
+#endif
+
/****************************************************************************
Read data from a socket with a timout in msec.
mincount = if timeout, minimum to read before returning