diff options
author | Andrew Tridgell <tridge@samba.org> | 1996-06-07 03:34:22 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1996-06-07 03:34:22 +0000 |
commit | d160d93d8fad563400aa1e1274437df1fbd4ecbf (patch) | |
tree | d6304b986418030366e6e8a9462dd6cd6ddcf72d /source3/lib | |
parent | bb0a9664f56c168e11e6b127909f558e3b4f313d (diff) | |
download | samba-d160d93d8fad563400aa1e1274437df1fbd4ecbf.tar.gz samba-d160d93d8fad563400aa1e1274437df1fbd4ecbf.tar.bz2 samba-d160d93d8fad563400aa1e1274437df1fbd4ecbf.zip |
- added predict.c, moving the routines from util.c
- added iface_count() and iface_n_ip() routines so its easy to loop
over the local interface list
- made readsize a normal loadparm global
- check for null w in add_domain_entry()
- set the deathtime to time()-1 for doamin entries with servertype==0
This allows servers that are shutting down to be removed
- add the 0x1c name at startup if we are a WINS server. Previously we
added it only if we were a master
- loop over interfaces in add_my_domains(), so people don't have to
have a lmhosts file to get lp_workgroup() on all interfaces
- set add to True for find_workgroupstruct() in nmbsync, and check for
null return
- remove some ugly "errno = EBADF" bits. they just confused things.
(This used to be commit 88b191b48836eeb7937f25b37d0bdd4a2276e5a7)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/interface.c | 27 | ||||
-rw-r--r-- | source3/lib/util.c | 134 |
2 files changed, 32 insertions, 129 deletions
diff --git a/source3/lib/interface.c b/source3/lib/interface.c index a47ef6e47e..f2a535d80c 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -388,6 +388,33 @@ BOOL ismybcast(struct in_addr bcast) return False; } +/**************************************************************************** + how many interfaces do we have + **************************************************************************/ +int iface_count(void) +{ + int ret = 0; + struct interface *i; + + for (i=interfaces;i;i=i->next) + ret++; + return ret; +} + +/**************************************************************************** + return IP of the Nth interface + **************************************************************************/ +struct in_addr *iface_n_ip(int n) +{ + struct interface *i; + + for (i=interfaces;i && n;i=i->next) + n--; + + if (i) return &i->ip; + return NULL; +} + static struct interface *iface_find(struct in_addr ip) { struct interface *i; diff --git a/source3/lib/util.c b/source3/lib/util.c index 6cc9a7e172..cfe8ea05b0 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -56,10 +56,6 @@ int trans_num = 0; */ int case_default = CASE_LOWER; - -/* size of reads during a direct file to file transfer */ -int ReadSize = 16*1024; - pstring debugf = "/tmp/log.samba"; int syslog_level; @@ -1951,7 +1947,6 @@ int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out,BOOL /* Check if error */ if(selrtn == -1) { - errno = EBADF; return -1; } @@ -1974,7 +1969,6 @@ int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out,BOOL /* force a particular error number for portability */ DEBUG(5,("read gave error %s\n",strerror(errno))); - errno = EBADF; return -1; } @@ -2068,10 +2062,6 @@ int read_data(int fd,char *buffer,int N) { ret = read(fd,buffer + total,N - total); - /* this is for portability */ - if (ret < 0) - errno = EBADF; - if (ret <= 0) return total; total += ret; @@ -2101,142 +2091,28 @@ int write_data(int fd,char *buffer,int N) } -/* variables used by the read prediction module */ -int rp_fd = -1; -int rp_offset = 0; -int rp_length = 0; -int rp_alloced = 0; -int rp_predict_fd = -1; -int rp_predict_offset = 0; -int rp_predict_length = 0; -int rp_timeout = 5; -time_t rp_time = 0; -char *rp_buffer = NULL; -BOOL predict_skip=False; -time_t smb_last_time=(time_t)0; - -/**************************************************************************** -handle read prediction on a file -****************************************************************************/ -int read_predict(int fd,int offset,char *buf,char **ptr,int num) -{ - int ret = 0; - int possible = rp_length - (offset - rp_offset); - - possible = MIN(possible,num); - - /* give data if possible */ - if (fd == rp_fd && - offset >= rp_offset && - possible>0 && - smb_last_time-rp_time < rp_timeout) - { - ret = possible; - if (buf) - memcpy(buf,rp_buffer + (offset-rp_offset),possible); - else - *ptr = rp_buffer + (offset-rp_offset); - DEBUG(5,("read-prediction gave %d bytes of %d\n",ret,num)); - } - - if (ret == num) { - predict_skip = True; - } else { - predict_skip = False; - - /* prepare the next prediction */ - rp_predict_fd = fd; - rp_predict_offset = offset + num; - rp_predict_length = num; - } - - if (ret < 0) ret = 0; - - return(ret); -} - -/**************************************************************************** -pre-read some data -****************************************************************************/ -void do_read_prediction() -{ - if (predict_skip) return; - - if (rp_predict_fd == -1) - return; - - rp_fd = rp_predict_fd; - rp_offset = rp_predict_offset; - rp_length = 0; - - rp_predict_fd = -1; - - rp_predict_length = MIN(rp_predict_length,2*ReadSize); - rp_predict_length = MAX(rp_predict_length,1024); - rp_offset = (rp_offset/1024)*1024; - rp_predict_length = (rp_predict_length/1024)*1024; - - if (rp_predict_length > rp_alloced) - { - rp_buffer = Realloc(rp_buffer,rp_predict_length); - rp_alloced = rp_predict_length; - if (!rp_buffer) - { - DEBUG(0,("can't allocate read-prediction buffer\n")); - rp_predict_fd = -1; - rp_fd = -1; - rp_alloced = 0; - return; - } - } - - if (lseek(rp_fd,rp_offset,SEEK_SET) != rp_offset) { - rp_fd = -1; - rp_predict_fd = -1; - return; - } - - rp_length = read(rp_fd,rp_buffer,rp_predict_length); - rp_time = time(NULL); - if (rp_length < 0) - rp_length = 0; -} - -/**************************************************************************** -invalidate read-prediction on a fd -****************************************************************************/ -void invalidate_read_prediction(int fd) -{ - if (rp_fd == fd) - rp_fd = -1; - if (rp_predict_fd == fd) - rp_predict_fd = -1; -} - - /**************************************************************************** transfer some data between two fd's ****************************************************************************/ int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align) { static char *buf=NULL; + static int size=0; char *buf1,*abuf; - static int size = 0; int total = 0; DEBUG(4,("transfer_file %d (head=%d) called\n",n,headlen)); - if ((size < ReadSize) && buf) { - free(buf); - buf = NULL; + if (size == 0) { + size = lp_readsize(); + size = MAX(size,1024); } - size = MAX(ReadSize,1024); - while (!buf && size>0) { buf = (char *)Realloc(buf,size+8); if (!buf) size /= 2; } + if (!buf) { DEBUG(0,("Can't allocate transfer buffer!\n")); exit(1); |