Commit dd338a91 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(isc_tcp_accept_fn): isc_createtcp will close the file descriptor if

	it fails, so don't re-close it here.  isc_createtcp will also
	set the fd attribute of the session; don't set it again.
(isc_createtcp): Relocate the fd.  Be careful to always close it
	if an error occurs.
parent 9c4985ee
...@@ -58,13 +58,9 @@ isc_tcp_accept_fn(IscHandlerList *UNUSED(hl), ...@@ -58,13 +58,9 @@ isc_tcp_accept_fn(IscHandlerList *UNUSED(hl),
new_scb = isc_createtcp(scb->cfg, fd); new_scb = isc_createtcp(scb->cfg, fd);
if (!new_scb) if (!new_scb)
{
close(fd);
return NULL; return NULL;
}
/* Fill in the session info structure */ /* Fill in the session info structure */
new_scb->fd = fd;
new_scb->state = ISC_STATE_RUNNING; new_scb->state = ISC_STATE_RUNNING;
new_scb->mode = O_RDWR; new_scb->mode = O_RDWR;
new_scb->info.tcp.raddr = isc_getraddress(new_scb); new_scb->info.tcp.raddr = isc_getraddress(new_scb);
...@@ -160,7 +156,8 @@ isc_mktcpaddress(const char *address, ...@@ -160,7 +156,8 @@ isc_mktcpaddress(const char *address,
/* /*
** Create a TCP session ** Create a TCP session.
** Will close fd and return NULL if an error occurs.
*/ */
IscSession * IscSession *
isc_createtcp(IscSessionConfig *cfg, int fd) isc_createtcp(IscSessionConfig *cfg, int fd)
...@@ -174,6 +171,8 @@ isc_createtcp(IscSessionConfig *cfg, int fd) ...@@ -174,6 +171,8 @@ isc_createtcp(IscSessionConfig *cfg, int fd)
if (fd == -1) if (fd == -1)
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return NULL; return NULL;
fd = isc_relocate_fd(fd, cfg->fd_relocate);
/* Set non blocking write mode */ /* Set non blocking write mode */
if ((res = fcntl(fd, F_GETFL, 0)) == -1) if ((res = fcntl(fd, F_GETFL, 0)) == -1)
...@@ -208,7 +207,10 @@ isc_createtcp(IscSessionConfig *cfg, int fd) ...@@ -208,7 +207,10 @@ isc_createtcp(IscSessionConfig *cfg, int fd)
scb = isc_create(cfg, &isc_tcp_funs); scb = isc_create(cfg, &isc_tcp_funs);
if (!scb) if (!scb)
{
close(fd);
return NULL; return NULL;
}
scb->type = ISC_TYPE_TCP; scb->type = ISC_TYPE_TCP;
scb->fd = fd; scb->fd = fd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment