Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Refactor the mainrelay.c #1301

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft

Conversation

KangLin
Copy link
Contributor

@KangLin KangLin commented Oct 24, 2023

Refactor the mainrelay.c for add windows service.
See #1300

  • Replace exit() with an elegant way
  • Add free resource when the program exit

@KangLin KangLin force-pushed the refactor branch 12 times, most recently from 7d744fb to 36f5051 Compare October 26, 2023 05:10
@KangLin KangLin closed this Oct 26, 2023
@KangLin KangLin reopened this Oct 26, 2023
@KangLin KangLin marked this pull request as draft October 26, 2023 12:49
@KangLin KangLin marked this pull request as ready for review October 26, 2023 12:51
@KangLin KangLin marked this pull request as draft October 26, 2023 12:51
@KangLin KangLin force-pushed the refactor branch 7 times, most recently from 70c51a8 to 6896d6c Compare October 27, 2023 13:52
@KangLin KangLin marked this pull request as ready for review October 27, 2023 14:05
@KangLin
Copy link
Contributor Author

KangLin commented Oct 27, 2023

@SamuelMarks @eakraly @rolandwu777 @ggarber @pando-emil

Please review.

@KangLin KangLin force-pushed the refactor branch 3 times, most recently from 2ed5784 to 3609579 Compare October 29, 2023 13:09
@KangLin KangLin force-pushed the refactor branch 2 times, most recently from e933782 to 66f5cc8 Compare November 27, 2023 09:01
- add remove_listener()
- add remove_socket_per_thread_udp_listener_servers()
- add remove_socket_per_endpoint_udp_listener_servers()
- add remove_socket_per_session_udp_listener_servers()
- rename clean_server() to clean_dtls_listener_server()
- Remove exit() and free resource
- Remove goto
- Optimized "{}" multiple nesting,
- Replace c98 (restrict variable declaration position at the beginning of the block)
  with c11 (no restriction variable declaration position in the block)
- Optimized the multiple nesting and length of if{}.
relay_receive_auth_message()
Using non-blocking improves thread performance
- Remove exit() and free resource
- Remove goto
- Optimized "{}" multiple nesting,
- Replace c98 (restrict variable declaration position at the beginning of the block)
  with c11 (no restriction variable declaration position in the block)
- Replace perror with TURN_LOG_FUNC
- Remove goto
- Optimized "{}" multiple nesting,
- Replace c98 (restrict variable declaration position at the beginning of the block)
  with c11 (no restriction variable declaration position in the block)
  Optimized the multiple nesting and length of if{}.
void read_spare_buffer(evutil_socket_t fd) {
if (fd >= 0) {
static char buffer[65536];
#if defined(WINDOWS)
// TODO: add set no-block? by Kang Lin <kl222@126.com>
// Because of the fd is noblock socket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reword this comment? it is not easy to read.

@@ -114,8 +101,7 @@ int set_sock_buf_size(evutil_socket_t fd, int sz0) {
}

if (sz < 1) {
perror("Cannot set socket rcv size");
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Cannot set rcv sock size %d on fd %d\n", sz0, fd);
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Cannot set rcv sock size %d on fd %d, err:%d\n", sz0, fd, socket_errno());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if the socket_errno() was printed as a string and not (only) an integer.

@@ -114,8 +101,7 @@ int set_sock_buf_size(evutil_socket_t fd, int sz0) {
}

if (sz < 1) {
perror("Cannot set socket rcv size");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, if this function (set_sock_buf_size()) takes as it's second argument a variable that'll be cast to socklen_t then the parameter should be socklen_t... not int.

@@ -150,7 +135,7 @@ int socket_init(void) {
/* Tell the user that we could not find a usable */
/* Winsock DLL. */
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "WSAStartup failed with error: %d\n", e);
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the definition of wVersionRequested be changed to also provide the initial value? Better than doing it in two steps.

same for int e

if (addr->ss.sa_family == AF_INET) {
do {
ret = bind(fd, (const struct sockaddr *)addr, sizeof(struct sockaddr_in));
} while (ret < 0 && socket_eintr());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document what this loop is supposed to do?

why bind the same socket multiple times?

src/apps/relay/netengine.c Show resolved Hide resolved
@@ -935,6 +940,8 @@ static ioa_engine_handle create_new_listener_engine(void) {
&turn_params.redis_statsdb
#endif
);
if (NULL == e)
return e;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return e if e is null?

src/apps/relay/netengine.c Show resolved Hide resolved
@@ -943,73 +950,29 @@ static ioa_engine_handle create_new_listener_engine(void) {
static void *run_udp_listener_thread(void *arg) {
static int always_true = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erm.... this is not a great name for a variable...?
especially since it seems this specific variable does not accomplish anything.

src/apps/relay/netengine.c Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants