Skip to content

Commit 29a421a

Browse files
committed
Bump license
1 parent d2b799b commit 29a421a

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2020, Andrea Giacomo Baldan
3+
Copyright (c) 2023, Andrea Giacomo Baldan
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
.POSIX:
2-
CFLAGS=-std=c99 -Wall -Wextra -Werror -pedantic -D_DEFAULT_SOURCE=200809L
2+
CFLAGS=-std=c99 -Wall -Wextra -Werror -pedantic -D_DEFAULT_SOURCE=200809L -lpthread
33

44
echo-server: examples/echo_server.c ev.h
5-
$(CC) $(CFLAGS) examples/echo_server.c -o echo_server
5+
$(CC) $(CFLAGS) examples/echo_server.c -o echo_server
66

77
ping-pong: examples/ping_pong.c ev.h
8-
$(CC) $(CFLAGS) examples/ping_pong.c -o ping_pong
8+
$(CC) $(CFLAGS) examples/ping_pong.c -o ping_pong
99

1010
ev-tcp-server: examples/ev_tcp_server.c ev.h
11-
$(CC) $(CFLAGS) examples/ev_tcp_server.c -o ev_tcp_server
11+
$(CC) $(CFLAGS) examples/ev_tcp_server.c -o ev_tcp_server
1212

1313
ev-tcp-server-stats: examples/ev_tcp_server_stats.c ev.h
14-
$(CC) $(CFLAGS) examples/ev_tcp_server_stats.c -o ev_tcp_server_stats
14+
$(CC) $(CFLAGS) examples/ev_tcp_server_stats.c -o ev_tcp_server_stats
1515

1616
ev-tls-tcp-server: examples/ev_tls_tcp_server.c ev.h
17-
$(CC) $(CFLAGS) -DHAVE_OPENSSL=1 -lssl -lcrypto examples/ev_tls_tcp_server.c -o ev_tls_tcp_server
17+
$(CC) $(CFLAGS) -DHAVE_OPENSSL=1 -lssl -lcrypto examples/ev_tls_tcp_server.c -o ev_tls_tcp_server
1818

1919
all: echo-server ping-pong ev-tcp-server ev-tcp-server-stats ev-tls-tcp-server
2020

2121
clean:
22-
@rm echo_server ping_pong ev_tcp_server ev_tcp_server_stats ev_tls_tcp_server
22+
@rm echo_server ping_pong ev_tcp_server ev_tcp_server_stats ev_tls_tcp_server

ev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* BSD 2-Clause License
22
*
3-
* Copyright (c) 2020, Andrea Giacomo Baldan All rights reserved.
3+
* Copyright (c) 2023, Andrea Giacomo Baldan All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions are met:

ev_tcp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* BSD 2-Clause License
22
*
3-
* Copyright (c) 2020, Andrea Giacomo Baldan All rights reserved.
3+
* Copyright (c) 2023, Andrea Giacomo Baldan All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions are met:
@@ -534,8 +534,8 @@ static int client_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx) {
534534

535535
(void) ctx; // Unused
536536

537-
/* Preverify should check expiry, revocation. */
538-
return preverify_ok;
537+
/* Preverify should check expiry, revocation. */
538+
return preverify_ok;
539539
}
540540

541541
static void load_certificates(SSL_CTX *ctx, const char *ca,
@@ -547,10 +547,10 @@ static void load_certificates(SSL_CTX *ctx, const char *ca,
547547
}
548548

549549
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE|SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
550-
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, client_certificate_verify);
550+
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, client_certificate_verify);
551551
SSL_CTX_set_ecdh_auto(ctx, 1);
552552

553-
if (SSL_CTX_use_certificate_chain_file(ctx, cert) <= 0) {
553+
if (SSL_CTX_use_certificate_chain_file(ctx, cert) <= 0) {
554554
ERR_print_errors_fp(stderr);
555555
exit(EXIT_FAILURE);
556556
}

examples/echo_server.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdlib.h>
55
#include <unistd.h>
66
#include <sys/socket.h>
7+
#include <pthread.h>
78
#define EV_SOURCE // add before ev.h
89
#include "../ev.h"
910

@@ -130,7 +131,7 @@ static void on_data(ev_context *ctx, void *data) {
130131
return;
131132
}
132133

133-
printf("Received %lu bytes\n", conn->bufsize);
134+
/* printf("Received %lu bytes\n", conn->bufsize); */
134135

135136
/* Fire an event to schedule a response */
136137
ev_fire_event(ctx, conn->fd, EV_WRITE, on_response, conn);
@@ -168,6 +169,29 @@ static void on_response(ev_context *ctx, void *data) {
168169
fprintf(stderr, "write(2) - error sending data: %s\n", strerror(errno));
169170
}
170171

172+
static void *worker(void *data) {
173+
int listen_fd = *((int *) data);
174+
ev_context ctx;
175+
int err = ev_init(&ctx, 1024);
176+
if (err < EV_OK) {
177+
fprintf(stderr, "Ev context init failed: Out of memory");
178+
exit(EXIT_FAILURE);
179+
}
180+
181+
/* Register a callback on the listening socket for incoming connections */
182+
ev_register_event(&ctx, listen_fd, EV_READ, on_connection, &listen_fd);
183+
184+
printf("Listening on %s:%i\n", HOST, PORT);
185+
186+
/* Start the loop */
187+
ev_run(&ctx);
188+
189+
/* Release resources after the loop has been stopped */
190+
ev_destroy(&ctx);
191+
192+
return NULL;
193+
}
194+
171195
int main(void) {
172196

173197
ev_context ctx;
@@ -210,10 +234,14 @@ int main(void) {
210234
if (listen(listen_fd, 32) != 0)
211235
goto err;
212236

213-
int err = ev_init(&ctx, 32);
237+
pthread_t handle[4];
238+
for (int i = 0; i < 4; i++) {
239+
pthread_create(&handle[i], NULL, (void * (*) (void *)) &worker, &listen_fd);
240+
}
241+
int err = ev_init(&ctx, 1024);
214242
if (err < EV_OK) {
215-
fprintf(stderr, "Ev context init failed: Out of memory");
216-
exit(EXIT_FAILURE);
243+
fprintf(stderr, "Ev context init failed: Out of memory");
244+
exit(EXIT_FAILURE);
217245
}
218246

219247
/* Register a callback on the listening socket for incoming connections */

0 commit comments

Comments
 (0)