[Spice-devel] [PATCH 2/6] Rename __reds_accept_connection into reds_init_client_connection
Daniel P. Berrange
berrange at redhat.com
Mon Dec 12 08:52:29 PST 2011
From: "Daniel P. Berrange" <berrange at redhat.com>
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 at redhat.com>
---
server/reds.c | 31 ++++++++++++++++++-------------
1 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index 10ebf19..fea09ad 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;
}
--
1.7.7.3
More information about the Spice-devel
mailing list