summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gibber/gibber-fd-transport.c23
-rw-r--r--lib/gibber/gibber-transport.c12
-rw-r--r--lib/gibber/gibber-transport.h6
3 files changed, 41 insertions, 0 deletions
diff --git a/lib/gibber/gibber-fd-transport.c b/lib/gibber/gibber-fd-transport.c
index a960424f..faf0c107 100644
--- a/lib/gibber/gibber-fd-transport.c
+++ b/lib/gibber/gibber-fd-transport.c
@@ -42,6 +42,10 @@ static void gibber_fd_transport_disconnect (GibberTransport *transport);
static gboolean gibber_fd_transport_get_peeraddr (GibberTransport *transport,
struct sockaddr_storage *addr, socklen_t *len);
+static gboolean gibber_fd_transport_get_sockaddr (GibberTransport *transport,
+ struct sockaddr_storage *addr,
+ socklen_t *len);
+
static void _do_disconnect (GibberFdTransport *self);
static gboolean gibber_fd_transport_buffer_is_empty (
@@ -119,6 +123,7 @@ gibber_fd_transport_class_init (
transport_class->send = gibber_fd_transport_send;
transport_class->disconnect = gibber_fd_transport_disconnect;
transport_class->get_peeraddr = gibber_fd_transport_get_peeraddr;
+ transport_class->get_sockaddr = gibber_fd_transport_get_sockaddr;
transport_class->buffer_is_empty = gibber_fd_transport_buffer_is_empty;
transport_class->block_receiving = gibber_fd_transport_block_receiving;
@@ -471,6 +476,24 @@ gibber_fd_transport_get_peeraddr (GibberTransport *transport,
}
static gboolean
+gibber_fd_transport_get_sockaddr (GibberTransport *transport,
+ struct sockaddr_storage *addr,
+ socklen_t *len)
+{
+ GibberFdTransport *self = GIBBER_FD_TRANSPORT (transport);
+
+ if (self->fd == -1)
+ {
+ DEBUG ("Someone requested the sockaddr while we're not connected");
+ return FALSE;
+ }
+
+ *len = sizeof (struct sockaddr_storage);
+
+ return (getsockname (self->fd, (struct sockaddr *) addr, len) == 0);
+}
+
+static gboolean
gibber_fd_transport_buffer_is_empty (GibberTransport *transport)
{
GibberFdTransport *self = GIBBER_FD_TRANSPORT (transport);
diff --git a/lib/gibber/gibber-transport.c b/lib/gibber/gibber-transport.c
index bb78dc8c..82ad73b3 100644
--- a/lib/gibber/gibber-transport.c
+++ b/lib/gibber/gibber-transport.c
@@ -258,6 +258,18 @@ gibber_transport_get_peeraddr (GibberTransport *transport,
}
gboolean
+gibber_transport_get_sockaddr (GibberTransport *transport,
+ struct sockaddr_storage *addr, socklen_t *len)
+{
+ GibberTransportClass *cls = GIBBER_TRANSPORT_GET_CLASS (transport);
+
+ if (cls->get_sockaddr != NULL)
+ return cls->get_sockaddr (transport, addr, len);
+
+ return FALSE;
+}
+
+gboolean
gibber_transport_buffer_is_empty (GibberTransport *transport)
{
GibberTransportClass *cls = GIBBER_TRANSPORT_GET_CLASS (transport);
diff --git a/lib/gibber/gibber-transport.h b/lib/gibber/gibber-transport.h
index aec12641..cf9b435e 100644
--- a/lib/gibber/gibber-transport.h
+++ b/lib/gibber/gibber-transport.h
@@ -54,6 +54,8 @@ struct _GibberTransportClass {
void (*disconnect) (GibberTransport *transport);
gboolean (*get_peeraddr) (GibberTransport *transport,
struct sockaddr_storage *addr, socklen_t *len);
+ gboolean (*get_sockaddr) (GibberTransport *transport,
+ struct sockaddr_storage *addr, socklen_t *len);
gboolean (*buffer_is_empty) (GibberTransport *transport);
void (*block_receiving) (GibberTransport *transport, gboolean block);
};
@@ -113,6 +115,10 @@ void gibber_transport_set_handler (GibberTransport *transport,
gboolean gibber_transport_get_peeraddr (GibberTransport *transport,
struct sockaddr_storage *addr, socklen_t *len);
+gboolean gibber_transport_get_sockaddr (GibberTransport *transport,
+ struct sockaddr_storage *addr,
+ socklen_t *len);
+
gboolean gibber_transport_buffer_is_empty (GibberTransport *transport);
void gibber_transport_emit_buffer_empty (GibberTransport *transport);