Skip to content

Commit

Permalink
socket: add listen feature
Browse files Browse the repository at this point in the history
Add a flag to tell whether the channel socket is listening.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1466105332-10285-3-git-send-email-marcandre.lureau@redhat.com>
Acked-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Jun 29, 2016
1 parent c1111a2 commit 3fa27a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/io/channel.h
Expand Up @@ -42,6 +42,7 @@ typedef enum QIOChannelFeature QIOChannelFeature;
enum QIOChannelFeature {
QIO_CHANNEL_FEATURE_FD_PASS = (1 << 0),
QIO_CHANNEL_FEATURE_SHUTDOWN = (1 << 1),
QIO_CHANNEL_FEATURE_LISTEN = (1 << 2),
};


Expand Down
7 changes: 7 additions & 0 deletions io/channel-socket.c
Expand Up @@ -71,6 +71,9 @@ qio_channel_socket_set_fd(QIOChannelSocket *sioc,
int fd,
Error **errp)
{
int val;
socklen_t len = sizeof(val);

if (sioc->fd != -1) {
error_setg(errp, "Socket is already open");
return -1;
Expand Down Expand Up @@ -106,6 +109,10 @@ qio_channel_socket_set_fd(QIOChannelSocket *sioc,
ioc->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS);
}
#endif /* WIN32 */
if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val) {
QIOChannel *ioc = QIO_CHANNEL(sioc);
ioc->features |= (1 << QIO_CHANNEL_FEATURE_LISTEN);
}

return 0;

Expand Down

0 comments on commit 3fa27a9

Please sign in to comment.