# arch-tag: automatic-ChangeLog--srvx@srvx.net--2006/srvx--devo--1.3
#
+2006-09-23 01:14:35 GMT Michael Poole <mdpoole@troilus.org> patch-49
+
+ Summary:
+ ioset event handling fixups
+ Revision:
+ srvx--devo--1.3--patch-49
+
+ src/ioset.c (ioset_connect): Properly handle the situation if the connect
+ handler closes the fd.
+ (ioset_accept): Rename "old_active_fd" to "old_active" for consistency.
+ (ioset_buffered_read): Make sure we bail if the fd is closed.
+ (ioset_events): Handle 'readable' on a connecting fd as an error.
+
+ modified files:
+ ChangeLog src/ioset.c
+
+
2006-09-23 01:03:08 GMT Michael Poole <mdpoole@troilus.org> patch-48
Summary:
struct io_fd *
ioset_connect(struct sockaddr *local, unsigned int sa_size, const char *peer, unsigned int port, int blocking, void *data, void (*connect_cb)(struct io_fd *fd, int error)) {
- int fd, res;
+ struct addrinfo hints;
+ struct addrinfo *ai;
struct io_fd *io_fd;
- struct addrinfo hints, *ai;
+ struct io_fd *old_active;
+ int res;
+ int fd;
char portnum[10];
memset(&hints, 0, sizeof(hints));
}
}
io_fd->state = IO_CONNECTED;
+ old_active = active_fd;
if (connect_cb)
connect_cb(io_fd, ((res < 0) ? errno : 0));
- engine->update(io_fd);
+ if (active_fd)
+ engine->update(io_fd);
+ if (old_active != io_fd)
+ active_fd = old_active;
return io_fd;
}
static void
ioset_accept(struct io_fd *listener)
{
- struct io_fd *old_active_fd;
+ struct io_fd *old_active;
struct io_fd *new_fd;
int fd;
new_fd = ioset_add(fd);
new_fd->state = IO_CONNECTED;
- old_active_fd = active_fd;
+ old_active = active_fd;
active_fd = new_fd;
listener->accept_cb(listener, new_fd);
assert(active_fd == NULL || active_fd == new_fd);
else
engine->update(new_fd);
}
- active_fd = old_active_fd;
+ active_fd = old_active;
}
static int
fdnum = fd->fd;
while (fd->wants_reads && (fd->line_len > 0)) {
struct io_fd *old_active;
+ int died = 0;
old_active = active_fd;
active_fd = fd;
fd->readable_cb(fd);
if (active_fd)
ioset_find_line_length(fd);
+ else
+ died = 1;
if (old_active != fd)
active_fd = old_active;
+ if (died)
+ break;
}
}
}
break;
case IO_CONNECTING:
assert(active_fd == NULL || active_fd == fd);
- if (active_fd && writable) {
+ if (active_fd && readable) {
socklen_t arglen;
int rc;
arglen = sizeof(rc);
if (getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &rc, &arglen) < 0)
rc = errno;
- fd->state = IO_CONNECTED;
+ fd->state = IO_CLOSED;
if (fd->connect_cb)
fd->connect_cb(fd, rc);
- if (active_fd == fd)
- engine->update(fd);
+ } else if (active_fd && writable) {
+ fd->state = IO_CONNECTED;
+ if (fd->connect_cb)
+ fd->connect_cb(fd, 0);
}
+ if (active_fd != fd)
+ break;
+ engine->update(fd);
/* and fall through */
case IO_CONNECTED:
assert(active_fd == NULL || active_fd == fd);