1 // ------------------------------------------------
7 // (c) 2002 peercast.org
8 // ------------------------------------------------
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 // ------------------------------------------------
27 //#define DISABLE_NAGLE 1
32 SocketBuffer(const void *p, int l){
37 ctime = sys->getTime();
38 memcpy((void*)buf, p, l);
53 class SocketBufferList {
63 bool isNull(){ return (top == NULL); }
64 void add(const void *p, int l){
65 SocketBuffer *tmp = new SocketBuffer(p,l);
75 // LOG_DEBUG("tmp = %d, top = %d, last = %d", tmp, top, last);
78 SocketBuffer *getTop(){
79 unsigned int ctime = sys->getTime();
82 if (top && (top->ctime + 10 >= ctime)){
85 // LOG_DEBUG("over 10sec(data skip)");
87 lastSkipTime = sys->getTime();
95 // LOG_DEBUG("oldtop = %d", top);
96 SocketBuffer *tmp = top;
103 // LOG_DEBUG("newtop = %d",top);
108 SocketBuffer *tmp = top;
118 unsigned int skipCount;
119 unsigned int lastSkipTime;
123 // --------------------------------------------------
124 class ClientSocket : public Stream
131 writeTimeout = 30000;
144 // required interface
145 virtual void open(Host &) = 0;
146 virtual void bind(Host &) = 0;
147 virtual void connect() = 0;
148 virtual bool active() = 0;
149 virtual ClientSocket *accept() = 0;
150 virtual Host getLocalHost() = 0;
152 virtual void setReadTimeout(unsigned int t)
156 virtual void setWriteTimeout(unsigned int t)
160 virtual void setBlocking(bool) {}
163 static unsigned int getIP(char *);
164 static bool getHostname(char *,unsigned int);
168 return active()==false;
174 SocketBufferList bufList;
175 virtual void bufferingWrite(const void *, int) = 0;
176 unsigned int skipCount;
177 unsigned int lastSkipTime;
180 unsigned int readTimeout,writeTimeout;