mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
unix sockets: a bunch of bugfixes
This commit is contained in:
+32
-11
@@ -81,7 +81,7 @@ int unsocket_bind(struct _socket_t* sock, sockaddr_un* addr, socklen_t addrlen){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unsocket_connect(struct _socket_t* sock, void* addr, socklen_t addrlen){
|
int unsocket_connect(struct _socket_t* sock, void* addr, socklen_t addrlen, fd_t* fd){
|
||||||
|
|
||||||
// copy address
|
// copy address
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ int unsocket_connect(struct _socket_t* sock, void* addr, socklen_t addrlen){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unsocket_accept(socket_t** peer, socket_t* sock, void* addr, socklen_t* addrlen){
|
int unsocket_accept(socket_t** peer, socket_t* sock, void* addr, socklen_t* addrlen, fd_t* fd){
|
||||||
|
|
||||||
// TODO abort
|
// TODO abort
|
||||||
|
|
||||||
@@ -197,6 +197,11 @@ int unsocket_accept(socket_t** peer, socket_t* sock, void* addr, socklen_t* addr
|
|||||||
// TODO interruptble
|
// TODO interruptble
|
||||||
|
|
||||||
while(!sock->backlogend){
|
while(!sock->backlogend){
|
||||||
|
if(fd->flags & O_NONBLOCK){
|
||||||
|
err = EWOULDBLOCK;
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
spinlock_release(&sock->lock);
|
spinlock_release(&sock->lock);
|
||||||
event_wait(&sock->connectevent, true);
|
event_wait(&sock->connectevent, true);
|
||||||
spinlock_acquire(&sock->lock);
|
spinlock_acquire(&sock->lock);
|
||||||
@@ -212,7 +217,7 @@ int unsocket_accept(socket_t** peer, socket_t* sock, void* addr, socklen_t* addr
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unsocket_send(socket_t* socket, void* buff, socklen_t len, int flags, int* error){
|
int unsocket_send(socket_t* socket, void* buff, size_t len, int flags, int* error, fd_t* fd){
|
||||||
|
|
||||||
if(flags){ // right now no flags are supported
|
if(flags){ // right now no flags are supported
|
||||||
*error = EOPNOTSUPP;
|
*error = EOPNOTSUPP;
|
||||||
@@ -220,6 +225,7 @@ int unsocket_send(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
}
|
}
|
||||||
|
|
||||||
int writec = 0;
|
int writec = 0;
|
||||||
|
*error = 0;
|
||||||
|
|
||||||
socket_t* peer = socket->peer;
|
socket_t* peer = socket->peer;
|
||||||
|
|
||||||
@@ -236,13 +242,20 @@ int unsocket_send(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
writec = ringbuffer_write(&peer->buffer, buff, len);
|
writec = ringbuffer_write(&peer->buffer, buff, len);
|
||||||
|
|
||||||
|
|
||||||
if(writec > 0){
|
if(writec > 0){
|
||||||
event_signal(&peer->dataevent, true);
|
event_signal(&peer->dataevent, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(fd->flags & O_NONBLOCK){
|
||||||
|
*error = EWOULDBLOCK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
spinlock_release(&peer->lock);
|
spinlock_release(&peer->lock);
|
||||||
|
|
||||||
|
|
||||||
if(event_wait(&peer->dataevent, true)){
|
if(event_wait(&peer->dataevent, true)){
|
||||||
spinlock_acquire(&peer->lock);
|
spinlock_acquire(&peer->lock);
|
||||||
writec = -1;
|
writec = -1;
|
||||||
@@ -253,8 +266,6 @@ int unsocket_send(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*error = 0;
|
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
spinlock_release(&peer->lock);
|
spinlock_release(&peer->lock);
|
||||||
@@ -266,7 +277,7 @@ int unsocket_send(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
// TODO check for broken
|
// TODO check for broken
|
||||||
|
|
||||||
int unsocket_recv(socket_t* socket, void* buff, socklen_t len, int flags, int* error){
|
int unsocket_recv(socket_t* socket, void* buff, size_t len, int flags, int* error, fd_t* fd){
|
||||||
|
|
||||||
if(flags){ // right now no flags are supported
|
if(flags){ // right now no flags are supported
|
||||||
*error = EOPNOTSUPP;
|
*error = EOPNOTSUPP;
|
||||||
@@ -275,6 +286,8 @@ int unsocket_recv(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
int readc = 0;
|
int readc = 0;
|
||||||
|
|
||||||
|
*error = 0;
|
||||||
|
|
||||||
spinlock_acquire(&socket->lock);
|
spinlock_acquire(&socket->lock);
|
||||||
|
|
||||||
if(socket->state != SOCKET_STATE_CONNECTED){
|
if(socket->state != SOCKET_STATE_CONNECTED){
|
||||||
@@ -288,11 +301,18 @@ int unsocket_recv(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
readc = ringbuffer_read(&socket->buffer, buff, len);
|
readc = ringbuffer_read(&socket->buffer, buff, len);
|
||||||
|
|
||||||
|
arch_interrupt_enable();
|
||||||
|
|
||||||
if(readc > 0){
|
if(readc > 0){
|
||||||
event_signal(&socket->dataevent, true);
|
event_signal(&socket->dataevent, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(fd->flags & O_NONBLOCK){
|
||||||
|
*error = EWOULDBLOCK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
spinlock_release(&socket->lock);
|
spinlock_release(&socket->lock);
|
||||||
|
|
||||||
if(event_wait(&socket->dataevent, true)){
|
if(event_wait(&socket->dataevent, true)){
|
||||||
@@ -306,8 +326,6 @@ int unsocket_recv(socket_t* socket, void* buff, socklen_t len, int flags, int* e
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*error = 0;
|
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
spinlock_release(&socket->lock);
|
spinlock_release(&socket->lock);
|
||||||
@@ -322,8 +340,9 @@ int unsocket_poll(socket_t* socket, pollfd* fd){
|
|||||||
|
|
||||||
switch(socket->state){
|
switch(socket->state){
|
||||||
case SOCKET_STATE_LISTENING:
|
case SOCKET_STATE_LISTENING:
|
||||||
if(fd->events & POLLIN && socket->backlogend)
|
if((fd->events & POLLIN) && socket->backlogend){
|
||||||
fd->revents |= POLLIN;
|
fd->revents |= POLLIN;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SOCKET_STATE_CONNECTED:
|
case SOCKET_STATE_CONNECTED:
|
||||||
@@ -331,11 +350,13 @@ int unsocket_poll(socket_t* socket, pollfd* fd){
|
|||||||
if(!socket->peer)
|
if(!socket->peer)
|
||||||
fd->revents |= POLLHUP;
|
fd->revents |= POLLHUP;
|
||||||
|
|
||||||
if(fd->events & POLLIN && socket->buffer.write != socket->buffer.read)
|
if((fd->events & POLLIN) && socket->buffer.write != socket->buffer.read){
|
||||||
fd->revents |= POLLIN;
|
fd->revents |= POLLIN;
|
||||||
|
}
|
||||||
|
|
||||||
if(fd->events & POLLOUT && socket->buffer.write != socket->buffer.read + socket->buffer.size)
|
if((fd->events & POLLOUT) && socket->buffer.write != socket->buffer.read + socket->buffer.size){
|
||||||
fd->revents |= POLLOUT;
|
fd->revents |= POLLOUT;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user