11 #include "wvhttppool.h"
12 #include "wvbufstream.h"
16 bool WvHttpStream::global_enable_pipelining =
true;
17 int WvUrlStream::max_requests = 100;
21 WvString key(
"%s%s", n.remaddr, n.username);
28 bool _create_dirs,
bool _pipeline_test)
29 : url(_url), headers(_headers)
32 create_dirs = _create_dirs;
33 pipeline_test = _pipeline_test;
48 putstream = content_source;
54 WvUrlRequest::~WvUrlRequest()
60 void WvUrlRequest::done()
75 log(WvLog::Debug4,
"Adding a new url: '%s'\n", url->url);
77 assert(url->outstream);
82 waiting_urls.append(url,
false,
"waiting_url");
89 log(WvLog::Debug4,
"Removing an url: '%s'\n", url->url);
93 waiting_urls.unlink(url);
98 WvHttpPool::WvHttpPool()
99 : log(
"HTTP Pool",
WvLog::Debug), conns(10),
100 pipeline_incompatible(50)
102 log(
"Pool initializing.\n");
103 num_streams_created = 0;
107 WvHttpPool::~WvHttpPool()
109 log(
"Created %s individual session%s during this run.\n",
110 num_streams_created, num_streams_created == 1 ?
"" :
"s");
112 log(
"Error was: %s\n", errstr());
128 WvUrlStreamDict::Iter ci(conns);
129 for (ci.rewind(); ci.next(); )
135 WvUrlRequestList::Iter i(urls);
136 for (i.rewind(); i.next(); )
140 log(WvLog::Debug4,
"Checking dns for '%s'\n", i->url.gethost());
141 if (i->url.resolve())
154 WvUrlStreamDict::Iter ci(conns);
155 for (ci.rewind(); ci.next(); )
159 log(WvLog::Debug4,
"Selecting true because of a dead stream.\n");
166 WvUrlRequestList::Iter i(urls);
167 for (i.rewind(); i.next(); )
169 if ((!i->outstream && !i->inuse) || !i->url.isok())
175 log(
"URL not okay: '%s'\n", i->url);
189 log(WvLog::Debug4,
"Checking dns for '%s'\n", i->url.gethost());
190 if (i->url.resolve() || dns.
post_select(i->url.gethost(), si))
192 log(WvLog::Debug4,
"Selecting true because of '%s'\n", i->url);
206 WvUrlRequestList::Iter i(urls);
207 for (i.rewind(); i.next(); )
211 if (!i->outstream || !i->url.isok() || !i->url.resolve())
232 num_streams_created++;
233 if (!strncasecmp(i->url.getproto(),
"http", 4))
235 i->url.getproto() ==
"https",
236 pipeline_incompatible);
237 else if (!strcasecmp(i->url.getproto(),
"ftp"))
238 s =
new WvFtpStream(target.remaddr, target.username,
239 i->url.getpassword());
243 append(s,
false,
"http/ftp stream");
258 log(WvLog::Debug4,
"Adding a new url to pool: '%s'\n", _url);
261 urls.append(url,
true,
"addurl");
263 return url->outstream;
269 if (!s->target.username)
270 log(
"Unconnecting stream to %s.\n", s->target.remaddr);
272 log(
"Unconnecting stream to %s@%s.\n", s->target.username,
275 WvUrlRequestList::Iter i(urls);
276 for (i.rewind(); i.next(); )
278 if (i->instream == s)
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
virtual void execute()
The callback() function calls execute(), and then calls the user- specified callback if one is define...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
bool post_select(WvStringParm hostname, WvStream::SelectInfo &si)
determines whether the resolving process is complete.
void pre_select(WvStringParm hostname, WvStream::SelectInfo &si)
add all of our waiting fds to an fd_set for use with select().
virtual bool isok() const
return true if the stream is actually usable right now
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
WvString is an implementation of a simple and efficient printable-string class.
the data structure used by pre_select()/post_select() and internally by select().