mirror of
https://github.com/mirror/wget.git
synced 2025-01-09 20:00:59 +08:00
[svn] Renamed register_extended to register_transport.
This commit is contained in:
parent
a501e1c988
commit
4e58524e8f
@ -1,3 +1,8 @@
|
||||
2003-11-14 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* connect.c (register_transport): Renamed from register_extended.
|
||||
Explain the intended usage.
|
||||
|
||||
2003-11-14 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* url.c (uri_merge): Merging "foo" and "bar" should result in
|
||||
|
@ -711,10 +711,10 @@ sock_close (int fd)
|
||||
That way the user code can call xread(fd, ...) and we'll run read
|
||||
or SSL_read or whatever is necessary. */
|
||||
|
||||
static struct hash_table *extended_map;
|
||||
static int extended_map_modified_tick;
|
||||
static struct hash_table *transport_map;
|
||||
static int transport_map_modified_tick;
|
||||
|
||||
struct extended_info {
|
||||
struct transport_info {
|
||||
xreader_t reader;
|
||||
xwriter_t writer;
|
||||
xpoller_t poller;
|
||||
@ -722,55 +722,58 @@ struct extended_info {
|
||||
void *ctx;
|
||||
};
|
||||
|
||||
/* Register the handlers for operations on FD. This is meant
|
||||
primarily for transport layers like SSL that piggyback on sockets,
|
||||
but with their own readers, writers, etc. */
|
||||
/* Register the transport layer operations that will be used when
|
||||
reading, writing, and polling FD.
|
||||
|
||||
This should be used for transport layers like SSL that piggyback on
|
||||
sockets. FD should otherwise be a real socket, on which you can
|
||||
call getpeername, etc. */
|
||||
|
||||
void
|
||||
register_extended (int fd, xreader_t reader, xwriter_t writer,
|
||||
register_transport (int fd, xreader_t reader, xwriter_t writer,
|
||||
xpoller_t poller, xcloser_t closer, void *ctx)
|
||||
{
|
||||
struct extended_info *info;
|
||||
struct transport_info *info;
|
||||
|
||||
/* The file descriptor must be non-negative to be registered.
|
||||
Negative values are ignored by xclose(), and -1 cannot be used as
|
||||
hash key. */
|
||||
assert (fd >= 0);
|
||||
|
||||
info = xnew (struct extended_info);
|
||||
info = xnew (struct transport_info);
|
||||
info->reader = reader;
|
||||
info->writer = writer;
|
||||
info->poller = poller;
|
||||
info->closer = closer;
|
||||
info->ctx = ctx;
|
||||
if (!extended_map)
|
||||
extended_map = hash_table_new (0, NULL, NULL);
|
||||
hash_table_put (extended_map, (void *) fd, info);
|
||||
++extended_map_modified_tick;
|
||||
if (!transport_map)
|
||||
transport_map = hash_table_new (0, NULL, NULL);
|
||||
hash_table_put (transport_map, (void *) fd, info);
|
||||
++transport_map_modified_tick;
|
||||
}
|
||||
|
||||
/* When xread/xwrite are called multiple times in a loop, they should
|
||||
remember the INFO pointer instead of fetching it every time. It is
|
||||
not enough to compare FD to LAST_FD because FD might have been
|
||||
closed and reopened. modified_tick ensures that changes to
|
||||
extended_map will not be unnoticed.
|
||||
transport_map will not be unnoticed.
|
||||
|
||||
This is a macro because we want the static storage variables to be
|
||||
per-function. */
|
||||
|
||||
#define LAZY_RETRIEVE_INFO(info) do { \
|
||||
static struct extended_info *last_info; \
|
||||
static struct transport_info *last_info; \
|
||||
static int last_fd = -1, last_tick; \
|
||||
if (!extended_map) \
|
||||
if (!transport_map) \
|
||||
info = NULL; \
|
||||
else if (last_fd == fd && last_tick == extended_map_modified_tick) \
|
||||
else if (last_fd == fd && last_tick == transport_map_modified_tick) \
|
||||
info = last_info; \
|
||||
else \
|
||||
{ \
|
||||
info = hash_table_get (extended_map, (void *) fd); \
|
||||
info = hash_table_get (transport_map, (void *) fd); \
|
||||
last_fd = fd; \
|
||||
last_info = info; \
|
||||
last_tick = extended_map_modified_tick; \
|
||||
last_tick = transport_map_modified_tick; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@ -782,7 +785,7 @@ register_extended (int fd, xreader_t reader, xwriter_t writer,
|
||||
int
|
||||
xread (int fd, char *buf, int bufsize, double timeout)
|
||||
{
|
||||
struct extended_info *info;
|
||||
struct transport_info *info;
|
||||
LAZY_RETRIEVE_INFO (info);
|
||||
if (timeout == -1)
|
||||
timeout = opt.read_timeout;
|
||||
@ -813,7 +816,7 @@ int
|
||||
xwrite (int fd, char *buf, int bufsize, double timeout)
|
||||
{
|
||||
int res;
|
||||
struct extended_info *info;
|
||||
struct transport_info *info;
|
||||
LAZY_RETRIEVE_INFO (info);
|
||||
if (timeout == -1)
|
||||
timeout = opt.read_timeout;
|
||||
@ -852,15 +855,15 @@ xwrite (int fd, char *buf, int bufsize, double timeout)
|
||||
void
|
||||
xclose (int fd)
|
||||
{
|
||||
struct extended_info *info;
|
||||
struct transport_info *info;
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
/* We don't need to be extra-fast here, so save some code by
|
||||
avoiding LAZY_RETRIEVE_INFO. */
|
||||
/* Don't use LAZY_RETRIEVE_INFO because xclose() is only called once
|
||||
per socket, so that particular optimization wouldn't work. */
|
||||
info = NULL;
|
||||
if (extended_map)
|
||||
info = hash_table_get (extended_map, (void *) fd);
|
||||
if (transport_map)
|
||||
info = hash_table_get (transport_map, (void *) fd);
|
||||
|
||||
if (info && info->closer)
|
||||
info->closer (fd, info->ctx);
|
||||
@ -869,8 +872,8 @@ xclose (int fd)
|
||||
|
||||
if (info)
|
||||
{
|
||||
hash_table_remove (extended_map, (void *) fd);
|
||||
hash_table_remove (transport_map, (void *) fd);
|
||||
xfree (info);
|
||||
++extended_map_modified_tick;
|
||||
++transport_map_modified_tick;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ typedef int (*xreader_t) PARAMS ((int, char *, int, void *));
|
||||
typedef int (*xwriter_t) PARAMS ((int, char *, int, void *));
|
||||
typedef int (*xpoller_t) PARAMS ((int, double, int, void *));
|
||||
typedef void (*xcloser_t) PARAMS ((int, void *));
|
||||
void register_extended PARAMS ((int,
|
||||
void register_transport PARAMS ((int,
|
||||
xreader_t, xwriter_t, xpoller_t, xcloser_t,
|
||||
void *));
|
||||
|
||||
|
@ -335,10 +335,11 @@ ssl_connect (int fd)
|
||||
if (SSL_connect (ssl) <= 0 || ssl->state != SSL_ST_OK)
|
||||
goto err;
|
||||
|
||||
/* Register the FD to use our functions for read, write, etc. That
|
||||
way the rest of Wget can keep using xread, xwrite, and
|
||||
friends. */
|
||||
register_extended (fd, ssl_read, ssl_write, ssl_poll, ssl_close, ssl);
|
||||
/* Register FD with Wget's transport layer, i.e. arrange that
|
||||
SSL-enabled functions are used for reading, writing, and polling.
|
||||
That way the rest of Wget can keep using xread, xwrite, and
|
||||
friends and not care what happens underneath. */
|
||||
register_transport (fd, ssl_read, ssl_write, ssl_poll, ssl_close, ssl);
|
||||
DEBUGP (("Connected %d to SSL 0x%0lx\n", fd, (unsigned long) ssl));
|
||||
return ssl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user