@@ -349,16 +349,34 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
context);
}
+static int qio_channel_socket_post_accept(QIOChannelSocket *cioc,
+ Error **errp)
+{
+ cioc->localAddrLen = sizeof(cioc->localAddr);
+ if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
+ &cioc->localAddrLen) < 0) {
+ error_setg_errno(errp, errno,
+ "Unable to query local socket address");
+ return 1;
+ }
+
+#ifndef WIN32
+ if (cioc->localAddr.ss_family == AF_UNIX) {
+ QIOChannel *ioc_local = QIO_CHANNEL(cioc);
+ qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS);
+ }
+#endif /* WIN32 */
+
+ return 0;
+}
QIOChannelSocket *
qio_channel_socket_accept(QIOChannelSocket *ioc,
Error **errp)
{
- QIOChannelSocket *cioc;
+ QIOChannelSocket *cioc = qio_channel_socket_new();
- cioc = qio_channel_socket_new();
cioc->remoteAddrLen = sizeof(ioc->remoteAddr);
- cioc->localAddrLen = sizeof(ioc->localAddr);
retry:
trace_qio_channel_socket_accept(ioc);
@@ -372,24 +390,11 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
trace_qio_channel_socket_accept_fail(ioc);
goto error;
}
-
- if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
- &cioc->localAddrLen) < 0) {
- error_setg_errno(errp, errno,
- "Unable to query local socket address");
- goto error;
+ if (!qio_channel_socket_post_accept(cioc, errp)) {
+ trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
+ return cioc;
}
-#ifndef WIN32
- if (cioc->localAddr.ss_family == AF_UNIX) {
- QIOChannel *ioc_local = QIO_CHANNEL(cioc);
- qio_channel_set_feature(ioc_local, QIO_CHANNEL_FEATURE_FD_PASS);
- }
-#endif /* WIN32 */
-
- trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
- return cioc;
-
error:
object_unref(OBJECT(cioc));
return NULL;
Factor out the post-accept actions into a subroutine that can be used in a subsequent patch. No functional change. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- io/channel-socket.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)