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

getpeername should check if tcp connection has been fully established #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libs/exasock/exanic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,14 @@ exanic_tcp_connecting(struct exa_socket * restrict sock)
return exa_tcp_connecting(&ctx->tcp);
}

bool
exanic_tcp_established(struct exa_socket * restrict sock)
{
struct exanic_tcp * restrict ctx = sock->ctx.tcp;

return exa_tcp_established(&ctx->tcp);
}

bool
exanic_tcp_listening(struct exa_socket * restrict sock)
{
Expand Down
1 change: 1 addition & 0 deletions libs/exasock/exanic.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void exanic_tcp_connect(struct exa_socket * restrict sock,
void exanic_tcp_shutdown_write(struct exa_socket * restrict sock);
void exanic_tcp_reset(struct exa_socket * restrict sock);
bool exanic_tcp_connecting(struct exa_socket * restrict sock);
bool exanic_tcp_established(struct exa_socket * restrict sock);
bool exanic_tcp_listening(struct exa_socket * restrict sock);
bool exanic_tcp_writeable(struct exa_socket * restrict sock);
bool exanic_tcp_write_closed(struct exa_socket *sock);
Expand Down
6 changes: 5 additions & 1 deletion libs/exasock/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ int
getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
struct exa_socket * restrict sock = exa_socket_get(sockfd);
bool connected = false;
int ret;

TRACE_CALL("getpeername");
Expand All @@ -1209,7 +1210,10 @@ getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
exa_read_lock(&sock->lock);

if (!sock->connected)
connected = sock->connected;
if (SOCK_STREAM == sock->type)
connected = exanic_tcp_established(sock);
if (!connected)
{
errno = ENOTCONN;
ret = -1;
Expand Down
8 changes: 8 additions & 0 deletions libs/exasock/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ exa_tcp_connecting(struct exa_tcp_conn * restrict ctx)
state->state == EXA_TCP_SYN_RCVD;
}

static inline bool
exa_tcp_established(struct exa_tcp_conn * restrict ctx)
{
struct exa_tcp_state * restrict state = &ctx->state->p.tcp;

return EXA_TCP_ESTABLISHED == state->state;
}

/* Return true if the write side of the connection has closed */
static inline bool
exa_tcp_write_closed(struct exa_tcp_conn * restrict ctx)
Expand Down
3 changes: 1 addition & 2 deletions modules/exanic/exanic-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ exanic_i2c_bus_register(struct exanic *exanic, int port,
data->bit_data.udelay = 20;
data->bit_data.timeout = HZ;
data->bit_data.data = data;
data->exanic = exanic;

/* fill in i2c adapter */
adap->owner = THIS_MODULE;
Expand All @@ -564,8 +565,6 @@ exanic_i2c_bus_register(struct exanic *exanic, int port,
data->xfer_wrapped = adap->algo->master_xfer;
exanic_i2c_bit_algo.functionality = adap->algo->functionality;
adap->algo = &exanic_i2c_bit_algo;

data->exanic = exanic;
/* add to bus list */
list_add_tail(&data->link, &exanic->i2c_list);

Expand Down