Skip to content

Commit

Permalink
add us_socket_remote_port(int ssl, struct us_socket_t *s) (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Burckhardt authored Oct 13, 2023
1 parent ac4e90e commit bb86c9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/io_uring/io_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ int us_socket_local_port(int ssl, struct us_socket_t *s) {
return 0;
}

int us_socket_remote_port(int ssl, struct us_socket_t *s) {
return 0;
}

void us_socket_shutdown_read(int ssl, struct us_socket_t *s) {

}
Expand Down Expand Up @@ -132,4 +136,4 @@ void us_socket_shutdown(int ssl, struct us_socket_t *s) {

}

#endif
#endif
3 changes: 3 additions & 0 deletions src/libusockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s, int code, vo
/* Returns local port or -1 on failure. */
int us_socket_local_port(int ssl, struct us_socket_t *s);

/* Returns remote ephemeral port or -1 on failure. */
int us_socket_remote_port(int ssl, struct us_socket_t *s);

/* Copy remote (IP) address of socket, or fail with zero length. */
void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *length);

Expand Down
11 changes: 10 additions & 1 deletion src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ int us_socket_local_port(int ssl, struct us_socket_t *s) {
}
}

int us_socket_remote_port(int ssl, struct us_socket_t *s) {
struct bsd_addr_t addr;
if (bsd_remote_addr(us_poll_fd(&s->p), &addr)) {
return -1;
} else {
return bsd_addr_get_port(&addr);
}
}

void us_socket_shutdown_read(int ssl, struct us_socket_t *s) {
/* This syscall is idempotent so no extra check is needed */
bsd_shutdown_socket_read(us_poll_fd((struct us_poll_t *) s));
Expand Down Expand Up @@ -219,4 +228,4 @@ void us_socket_shutdown(int ssl, struct us_socket_t *s) {
}
}

#endif
#endif

0 comments on commit bb86c9c

Please sign in to comment.