Fix naive ctx allocation
This commit is contained in:
parent
d322a00a5d
commit
8fc0d16e85
2 changed files with 10 additions and 5 deletions
|
@ -115,6 +115,8 @@ void algo_naive(struct algo_skel* as) {
|
|||
as->on_tcp_read.free_app_ctx = free_naive;
|
||||
as->on_tcp_read.cb = tcp_to_udp;
|
||||
as->on_tcp_read.socklist = NULL;
|
||||
if (as->on_tcp_read.app_ctx == NULL) goto init_err;
|
||||
memset(as->on_tcp_read.app_ctx, 0, sizeof(struct naive_ctx));
|
||||
|
||||
as->on_udp_read.name = "udp-read";
|
||||
as->on_udp_read.flags = EPOLLIN | EPOLLET;
|
||||
|
@ -122,6 +124,8 @@ void algo_naive(struct algo_skel* as) {
|
|||
as->on_udp_read.free_app_ctx = free_naive;
|
||||
as->on_udp_read.cb = tcp_to_udp;
|
||||
as->on_udp_read.socklist = NULL;
|
||||
if (as->on_udp_read.app_ctx == NULL) goto init_err;
|
||||
memset(as->on_udp_read.app_ctx, 0, sizeof(struct naive_ctx));
|
||||
|
||||
as->on_tcp_write.name = "tcp-write";
|
||||
as->on_tcp_write.flags = EPOLLOUT | EPOLLET;
|
||||
|
@ -137,8 +141,8 @@ void algo_naive(struct algo_skel* as) {
|
|||
as->on_udp_write.cb = tcp_to_udp;
|
||||
as->on_udp_write.socklist = NULL;
|
||||
|
||||
if (as->on_tcp_read.app_ctx == NULL || as->on_udp_read.app_ctx == NULL) {
|
||||
fprintf(stderr, "Failed to malloc naive_ctx\n");
|
||||
return;
|
||||
init_err:
|
||||
fprintf(stderr, "Failed to init algo naive\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,11 +66,12 @@ int create_tcp_server(char* service) {
|
|||
sock = socket(cursor->ai_family, cursor->ai_socktype, cursor->ai_protocol);
|
||||
if (sock == -1) continue;
|
||||
if (bind(sock, cursor->ai_addr, cursor->ai_addrlen) != -1) break;
|
||||
perror("bind failed");
|
||||
close(sock);
|
||||
}
|
||||
|
||||
if (cursor == NULL) {
|
||||
fprintf(stderr, "We failed to bind\n");
|
||||
fprintf(stderr, "We failed to create socket or bind\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue