svn commit: samba r7319 - in trunk/source/lib: .
jra at samba.org
jra at samba.org
Mon Jun 6 04:09:08 GMT 2005
Author: jra
Date: 2005-06-06 04:09:07 +0000 (Mon, 06 Jun 2005)
New Revision: 7319
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7319
Log:
Unify HEAD and 3.0 socket functions.
Jeremy.
Modified:
trunk/source/lib/util_sock.c
Changeset:
Modified: trunk/source/lib/util_sock.c
===================================================================
--- trunk/source/lib/util_sock.c 2005-06-06 04:07:10 UTC (rev 7318)
+++ trunk/source/lib/util_sock.c 2005-06-06 04:09:07 UTC (rev 7319)
@@ -241,7 +241,100 @@
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
maxcount = number to be read.
More information about the samba-cvs
mailing list