mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-02-02 15:07:36 -05:00
Feature: Added listensocket_container_set_sockcount_cb() and listensocket_container_sockcount()
This commit is contained in:
parent
5490120d4d
commit
c401bbcc12
@ -38,6 +38,8 @@ struct listensocket_container_tag {
|
|||||||
listensocket_t **sock;
|
listensocket_t **sock;
|
||||||
int *sockref;
|
int *sockref;
|
||||||
size_t sock_len;
|
size_t sock_len;
|
||||||
|
void (*sockcount_cb)(size_t count, void *userdata);
|
||||||
|
void *sockcount_userdata;
|
||||||
};
|
};
|
||||||
struct listensocket_tag {
|
struct listensocket_tag {
|
||||||
refobject_base_t __base;
|
refobject_base_t __base;
|
||||||
@ -54,6 +56,14 @@ static int listensocket__select_set(listensocket_t *self, fd_set *set, int *max)
|
|||||||
static int listensocket__select_isset(listensocket_t *self, fd_set *set);
|
static int listensocket__select_isset(listensocket_t *self, fd_set *set);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline void __call_sockcount_cb(listensocket_container_t *self)
|
||||||
|
{
|
||||||
|
if (self->sockcount_cb == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->sockcount_cb(listensocket_container_sockcount(self), self->sockcount_userdata);
|
||||||
|
}
|
||||||
|
|
||||||
static void listensocket_container_clear_sockets(listensocket_container_t *self)
|
static void listensocket_container_clear_sockets(listensocket_container_t *self)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -76,6 +86,8 @@ static void listensocket_container_clear_sockets(listensocket_container_t *self)
|
|||||||
free(self->sockref);
|
free(self->sockref);
|
||||||
self->sock = NULL;
|
self->sock = NULL;
|
||||||
self->sockref = NULL;
|
self->sockref = NULL;
|
||||||
|
|
||||||
|
__call_sockcount_cb(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,6 +106,8 @@ listensocket_container_t * listensocket_container_new(void)
|
|||||||
|
|
||||||
self->sock = NULL;
|
self->sock = NULL;
|
||||||
self->sock_len = 0;
|
self->sock_len = 0;
|
||||||
|
self->sockcount_cb = NULL;
|
||||||
|
self->sockcount_userdata = NULL;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -161,10 +175,13 @@ int listensocket_container_setup(listensocket_container_
|
|||||||
if (listensocket_refsock(self->sock[i]) == 0) {
|
if (listensocket_refsock(self->sock[i]) == 0) {
|
||||||
self->sockref[i] = 1;
|
self->sockref[i] = 1;
|
||||||
} else {
|
} else {
|
||||||
|
ICECAST_LOG_DEBUG("Can not ref socket.");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__call_sockcount_cb(self);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,6 +231,7 @@ static connection_t * listensocket_container_accept__inner(listensocket_co
|
|||||||
ICECAST_LOG_ERROR("Closing listen socket in error state.");
|
ICECAST_LOG_ERROR("Closing listen socket in error state.");
|
||||||
listensocket_unrefsock(socks[i]);
|
listensocket_unrefsock(socks[i]);
|
||||||
self->sockref[p] = 0;
|
self->sockref[p] = 0;
|
||||||
|
__call_sockcount_cb(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,6 +282,34 @@ connection_t * listensocket_container_accept(listensocket_container
|
|||||||
return listensocket_container_accept__inner(self, timeout);
|
return listensocket_container_accept__inner(self, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int listensocket_container_set_sockcount_cb(listensocket_container_t *self, void (*cb)(size_t count, void *userdata), void *userdata)
|
||||||
|
{
|
||||||
|
if (!self)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
self->sockcount_cb = cb;
|
||||||
|
self->sockcount_userdata = userdata;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t listensocket_container_sockcount(listensocket_container_t *self)
|
||||||
|
{
|
||||||
|
ssize_t count = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!self)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < self->sock_len; i++) {
|
||||||
|
if (self->sockref[i]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
static void __listensocket_free(refobject_t self, void **userdata)
|
static void __listensocket_free(refobject_t self, void **userdata)
|
||||||
{
|
{
|
||||||
listensocket_t *listensocket = REFOBJECT_TO_TYPE(self, listensocket_t *);
|
listensocket_t *listensocket = REFOBJECT_TO_TYPE(self, listensocket_t *);
|
||||||
|
@ -16,6 +16,8 @@ listensocket_container_t * listensocket_container_new(void);
|
|||||||
int listensocket_container_configure(listensocket_container_t *self, const ice_config_t *config);
|
int listensocket_container_configure(listensocket_container_t *self, const ice_config_t *config);
|
||||||
int listensocket_container_setup(listensocket_container_t *self);
|
int listensocket_container_setup(listensocket_container_t *self);
|
||||||
connection_t * listensocket_container_accept(listensocket_container_t *self, int timeout);
|
connection_t * listensocket_container_accept(listensocket_container_t *self, int timeout);
|
||||||
|
int listensocket_container_set_sockcount_cb(listensocket_container_t *self, void (*cb)(size_t count, void *userdata), void *userdata);
|
||||||
|
ssize_t listensocket_container_sockcount(listensocket_container_t *self);
|
||||||
|
|
||||||
int listensocket_refsock(listensocket_t *self);
|
int listensocket_refsock(listensocket_t *self);
|
||||||
int listensocket_unrefsock(listensocket_t *self);
|
int listensocket_unrefsock(listensocket_t *self);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user