Skip to content

Commit

Permalink
Fixed a couple of typos
Browse files Browse the repository at this point in the history
  • Loading branch information
codepr committed Nov 24, 2023
1 parent 4d15035 commit 2e33596
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
17 changes: 8 additions & 9 deletions ev.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ enum ev_type {
* The context is the main handler of the event loop and is meant to be passed
* around on each callback fired during the execution of the host application.
*
* Idealy it should be at most one context per thread, it's the user's duty to
* Ideally it should be at most one context per thread, it's the user's duty to
* take care of locking of possible shared parts and datastrutures but it's
* definetly a possibility to run multiple theads each one with his own loop,
* depending on the scenario, use-case by use-case it can be a feasible
Expand All @@ -162,7 +162,7 @@ typedef struct ev_ctx {
} ev_context;

/*
* Event struture used as the main carrier of clients informations, it will be
* Event structure used as the main carrier of clients information, it will be
* tracked by an array in every context created
*/
struct ev {
Expand All @@ -177,7 +177,7 @@ struct ev {
/*
* Initialize the ev_context, accepting the number of events to monitor; that
* value is indicative as if a FD exceeds the cap set the events array will be
* resized.
* resized accordingly.
* The first thing done is the initialization of the api pointer according to
* the Mux IO backend found on the host machine
*/
Expand Down Expand Up @@ -303,7 +303,6 @@ static int epoll_mod(int efd, int fd, int evs, void *data) {

// Being ev.data a union, in case of data != NULL, fd will be set to random
if (data) ev.data.ptr = data;

ev.events = evs | EPOLLHUP | EPOLLERR;

return epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
Expand Down Expand Up @@ -399,7 +398,7 @@ static inline struct ev *ev_api_fetch_event(const ev_context *ctx, int idx,
* The poll_api structure contains the number of fds to monitor and the array
* of pollfd structures associated. This number must be adjusted everytime a
* client disconnect or a new connection have an fd > nfds to avoid iterating
* over closed fds everytime a new event is triggered.
* over closed fds every time a new event is triggered.
* As select, poll iterate linearly over all the triggered events, without the
* hard limit of 1024 connections. It's the second best option available if no
* epoll or kqueue for Mac OSX are not present.
Expand Down Expand Up @@ -449,9 +448,9 @@ static int ev_api_poll(ev_context *ctx, time_t timeout) {
}

/*
* Poll maintain in his state the number of file descriptor it monitor in a
* Poll maintains in his state the number of file descriptors it monitors in a
* fixed size array just like the events we monitor over the primitive. If a
* resize is needed cause the number of fds have reached the length of the fds
* resize is needed due to the number of fds have reached the length of the fds
* array, we must increase its size.
*/
static int ev_api_watch_fd(ev_context *ctx, int fd) {
Expand Down Expand Up @@ -613,7 +612,7 @@ static int ev_api_del_fd(ev_context *ctx, int fd) {
if (FD_ISSET(fd, &s_api->rfds)) FD_CLR(fd, &s_api->rfds);
if (FD_ISSET(fd, &s_api->wfds)) FD_CLR(fd, &s_api->wfds);
/*
* To remove FD from select we must determine the new maximum descriptor
* To remove FD from select we must determine the new maximum descriptor
* value based on the bits that are still turned on in the rfds set.
*/
if (fd == ctx->maxfd) {
Expand Down Expand Up @@ -993,7 +992,7 @@ int ev_del_fd(ev_context *ctx, int fd) {
}

/*
* Register a new event, semantically it's equal to ev_register_event but
* Register a new event, semantically it's equal to ev_fire_event but
* it's meant to be used when an FD is not already watched by the event loop.
* It could be easily integrated in ev_fire_event call but I prefer maintain
* the samantic separation of responsibilities.
Expand Down
33 changes: 15 additions & 18 deletions ev_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* on non-blocking sockets and IO multiplexing using ev as underlying
* event-loop.
*
* As of now it's stll very simple, the only tweakable value is the buffer
* As of now it's still very simple, the only tweakable value is the buffer
* memory size for incoming and to-be-written stream of bytes for clients, the
* default value is 2048.
*
Expand Down Expand Up @@ -396,9 +396,9 @@ static void ev_on_recv(ev_context *ctx, void *data) {
if (handle->err == EV_TCP_SUCCESS) goto close;

/*
* If EAGAIN happened and there still more data to read, re-arm
* If EAGAIN happened and there is still more data to read, re-arm
* for a read on the next loop cycle, hopefully the kernel will be
* available to send remaining data
* available to send the remaining data
*/
if (handle->to_read > 0 && handle->buffer.size < handle->to_read &&
(errno == EAGAIN || errno == EWOULDBLOCK)) {
Expand All @@ -419,9 +419,9 @@ static void ev_on_send(ev_context *ctx, void *data) {
ev_tcp_handle *handle = data;
handle->err = ev_tcp_write(handle);
/*
* If EAGAIN happened and there still more data to be written out, re-arm
* If EAGAIN happened and there is still more data to be written out, re-arm
* for a write on the next loop cycle, hopefully the kernel will be
* available to send remaining data
* available to send the remaining data
*/
if (handle->buffer.size > 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
ev_tcp_enqueue_write(handle);
Expand Down Expand Up @@ -482,31 +482,30 @@ static int ev_connect(char *addr, int port) {
if (getaddrinfo(addr, portstr, &hints, &servinfo) != 0) return -1;

for (p = servinfo; p != NULL; p = p->ai_next) {
/* Try to create the socket and to connect it.
* If we fail in the socket() call, or on connect(), we retry with
* the next entry in servinfo. */
// Try to create the socket and to connect it.
// If we fail in the socket() call, or on connect(), we retry with
// the next entry in servinfo.
if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
continue;

/* Put in non blocking state if needed. */
// Put in non blocking state if needed
if (set_nonblocking(s) == -1) {
close(s);
break;
}

/* Try to connect. */
if (connect(s, p->ai_addr, p->ai_addrlen) == -1) {
/* If the socket is non-blocking, it is ok for connect() to
* return an EINPROGRESS error here. */
// If the socket is non-blocking, it is ok for connect() to
// return an EINPROGRESS error here.
if (errno == EINPROGRESS) return s;

/* Otherwise it's an error. */
// Otherwise it's an error
close(s);
break;
}

/* If we ended an iteration of the for loop without errors, we
* have a connected socket. Let's return to the caller. */
// If we ended an iteration of the for loop without errors, we
// have a connected socket. Let's return to the caller.
retval = s;
break;
}
Expand Down Expand Up @@ -905,9 +904,7 @@ void ev_tcp_fill_buffer(ev_tcp_handle *handle, const unsigned char *src,
ev_buf_copy(&handle->buffer, src, len);
}

void ev_tcp_zero_buffer(ev_tcp_handle *handle) {
ev_buf_zero(&handle->buffer);
}
void ev_tcp_zero_buffer(ev_tcp_handle *handle) { ev_buf_zero(&handle->buffer); }

ssize_t ev_tcp_read(ev_tcp_handle *client) {
#ifdef HAVE_OPENSSL
Expand Down

0 comments on commit 2e33596

Please sign in to comment.