summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2011-12-12 16:52:29 +0000
committerMarc-André Lureau <marcandre.lureau@redhat.com>2012-01-09 18:57:57 +0100
commit3a3a32ebbc3dbb644bdf53394ce5f925a7398f3a (patch)
tree9d3fba0c906f5291b1962edec6d5377689dc0030
parent4eb78d39c5acd33e419a6d9203557d309e3d7873 (diff)
downloadspice-3a3a32ebbc3dbb644bdf53394ce5f925a7398f3a.tar.gz
spice-3a3a32ebbc3dbb644bdf53394ce5f925a7398f3a.tar.xz
spice-3a3a32ebbc3dbb644bdf53394ce5f925a7398f3a.zip
Rename __reds_accept_connection into reds_init_client_connection
Remove the accept() call from __reds_accept_connection and rename it to reds_init_client_connection. The caller is now responsible for accepting the new socket. The method reds_init_client_connection merely initializes it for usage. * server/reds.c: Add reds_init_client_connection Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
-rw-r--r--server/reds.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/server/reds.c b/server/reds.c
index 10ebf193..fea09ad6 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2687,18 +2687,12 @@ static void reds_handle_ssl_accept(int fd, int event, void *data)
reds_handle_new_link(link);
}
-static RedLinkInfo *__reds_accept_connection(int listen_socket)
+static RedLinkInfo *reds_init_client_connection(int socket)
{
RedLinkInfo *link;
RedsStream *stream;
int delay_val = 1;
int flags;
- int socket;
-
- if ((socket = accept(listen_socket, NULL, 0)) == -1) {
- red_printf("accept failed, %s", strerror(errno));
- return NULL;
- }
if ((flags = fcntl(socket, F_GETFL)) == -1) {
red_printf("accept failed, %s", strerror(errno));
@@ -2731,8 +2725,6 @@ static RedLinkInfo *__reds_accept_connection(int listen_socket)
return link;
error:
- close(socket);
-
return NULL;
}
@@ -2743,12 +2735,17 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
int return_code;
int ssl_error;
BIO *sbio;
+ int socket;
- link = __reds_accept_connection(reds->secure_listen_socket);
- if (link == NULL) {
+ if ((socket = accept(reds->secure_listen_socket, NULL, 0)) == -1) {
+ red_printf("accept failed, %s", strerror(errno));
return;
}
+ link = reds_init_client_connection(socket);
+ if (link == NULL)
+ goto error;
+
// Handle SSL handshaking
if (!(sbio = BIO_new_socket(link->stream->socket, BIO_NOCLOSE))) {
red_printf("could not allocate ssl bio socket");
@@ -2789,7 +2786,7 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
SSL_free(link->stream->ssl);
error:
- close(link->stream->socket);
+ close(socket);
free(link->stream);
BN_free(link->tiTicketing.bn);
free(link);
@@ -2799,9 +2796,17 @@ static void reds_accept(int fd, int event, void *data)
{
RedLinkInfo *link;
RedsStream *stream;
+ int socket;
+
+ if ((socket = accept(reds->listen_socket, NULL, 0)) == -1) {
+ red_printf("accept failed, %s", strerror(errno));
+ return;
+ }
+
- if (!(link = __reds_accept_connection(reds->listen_socket))) {
+ if (!(link = reds_init_client_connection(socket))) {
red_printf("accept failed");
+ close(socket);
return;
}