[Spice-devel] [PATCH 2/6] Rename __reds_accept_connection into reds_init_client_connection
Daniel P. Berrange
berrange at redhat.com
Fri Oct 21 08:11:00 PDT 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 e3dd7bf..e7c9512 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2582,18 +2582,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));
@@ -2626,8 +2620,6 @@ static RedLinkInfo *__reds_accept_connection(int listen_socket)
return link;
error:
- close(socket);
-
return NULL;
}
@@ -2638,12 +2630,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");
@@ -2684,7 +2681,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);
@@ -2694,9 +2691,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.6.4
More information about the Spice-devel
mailing list