Skip to content

Commit

Permalink
ipc: ref count socket descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Nov 28, 2024
1 parent 36c165c commit e7249b1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/kernel/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct SocketDescriptor {
size_t *inboundLen, *outboundLen;
struct SocketDescriptor **backlog; // for incoming connections via connect()
struct SocketDescriptor *peer; // for peer-to-peer connections
int refCount;
} SocketDescriptor;

void socketInit();
Expand Down
1 change: 1 addition & 0 deletions src/ipc/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ int accept(Thread *t, int sd, struct sockaddr *addr, socklen_t *len) {

// copy the self address
SocketDescriptor *self = (SocketDescriptor *)iod->data;
self->refCount = 1;
memcpy(&self->address, &listener->address, sizeof(struct sockaddr));
self->type = listener->type;
self->protocol = listener->protocol;
Expand Down
1 change: 1 addition & 0 deletions src/ipc/sockinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ int socket(Thread *t, int domain, int type, int protocol) {

// set up the socket family for now
SocketDescriptor *sock = (SocketDescriptor *)iod->data;
sock->refCount = 1;
sock->process = p;
sock->address.sa_family = domain;
sock->type = type & 0xFF;
Expand Down

0 comments on commit e7249b1

Please sign in to comment.