Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast-Server
Commits
c401bbcc
Commit
c401bbcc
authored
May 09, 2018
by
Philipp Schafft
🦁
Browse files
Feature: Added listensocket_container_set_sockcount_cb() and listensocket_container_sockcount()
parent
5490120d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/listensocket.c
View file @
c401bbcc
...
...
@@ -38,6 +38,8 @@ struct listensocket_container_tag {
listensocket_t
**
sock
;
int
*
sockref
;
size_t
sock_len
;
void
(
*
sockcount_cb
)(
size_t
count
,
void
*
userdata
);
void
*
sockcount_userdata
;
};
struct
listensocket_tag
{
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
);
#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
)
{
size_t
i
;
...
...
@@ -76,6 +86,8 @@ static void listensocket_container_clear_sockets(listensocket_container_t *self)
free
(
self
->
sockref
);
self
->
sock
=
NULL
;
self
->
sockref
=
NULL
;
__call_sockcount_cb
(
self
);
}
...
...
@@ -94,6 +106,8 @@ listensocket_container_t * listensocket_container_new(void)
self
->
sock
=
NULL
;
self
->
sock_len
=
0
;
self
->
sockcount_cb
=
NULL
;
self
->
sockcount_userdata
=
NULL
;
return
self
;
}
...
...
@@ -161,10 +175,13 @@ int listensocket_container_setup(listensocket_container_
if
(
listensocket_refsock
(
self
->
sock
[
i
])
==
0
)
{
self
->
sockref
[
i
]
=
1
;
}
else
{
ICECAST_LOG_DEBUG
(
"Can not ref socket."
);
ret
=
1
;
}
}
__call_sockcount_cb
(
self
);
return
ret
;
}
...
...
@@ -214,6 +231,7 @@ static connection_t * listensocket_container_accept__inner(listensocket_co
ICECAST_LOG_ERROR
(
"Closing listen socket in error state."
);
listensocket_unrefsock
(
socks
[
i
]);
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
);
}
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
)
{
listensocket_t
*
listensocket
=
REFOBJECT_TO_TYPE
(
self
,
listensocket_t
*
);
...
...
src/listensocket.h
View file @
c401bbcc
...
...
@@ -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_setup
(
listensocket_container_t
*
self
);
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_unrefsock
(
listensocket_t
*
self
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment