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