mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
sockets: recv
This commit is contained in:
@@ -146,6 +146,9 @@ int vfs_read(int* error, vnode_t* node, void* buff, size_t count, size_t offset)
|
|||||||
|
|
||||||
int type = GETTYPE(node->st.st_mode);
|
int type = GETTYPE(node->st.st_mode);
|
||||||
|
|
||||||
|
if(type == TYPE_SOCKET)
|
||||||
|
return socket_recv(node->objdata, buff, count, 0, error);
|
||||||
|
|
||||||
if(type == TYPE_FIFO){
|
if(type == TYPE_FIFO){
|
||||||
return pipe_read(node->objdata, buff, count, error);
|
return pipe_read(node->objdata, buff, count, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,3 +92,12 @@ int socket_send(socket_t* socket, void* buff, size_t len, int flags, int* count)
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int socket_recv(socket_t* socket, void* buff, size_t len, int flags, int* count){
|
||||||
|
switch(socket->family){
|
||||||
|
case AF_UNIX:
|
||||||
|
return unsocket_recv(socket, buff, len, flags, count);
|
||||||
|
default:
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+50
-3
@@ -213,14 +213,12 @@ int unsocket_accept(socket_t** peer, socket_t* sock, void* addr, size_t* addrlen
|
|||||||
}
|
}
|
||||||
|
|
||||||
int unsocket_send(socket_t* socket, void* buff, size_t len, int flags, int* error){
|
int unsocket_send(socket_t* socket, void* buff, size_t len, int flags, int* error){
|
||||||
|
|
||||||
if(flags){ // right now no flags are supported
|
if(flags){ // right now no flags are supported
|
||||||
*error = EOPNOTSUPP;
|
*error = EOPNOTSUPP;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int err = 0;
|
|
||||||
int writec = 0;
|
int writec = 0;
|
||||||
|
|
||||||
socket_t* peer = socket->peer;
|
socket_t* peer = socket->peer;
|
||||||
@@ -265,3 +263,52 @@ int unsocket_send(socket_t* socket, void* buff, size_t len, int flags, int* erro
|
|||||||
return writec;
|
return writec;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unsocket_recv(socket_t* socket, void* buff, size_t len, int flags, int* error){
|
||||||
|
|
||||||
|
if(flags){ // right now no flags are supported
|
||||||
|
*error = EOPNOTSUPP;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readc = 0;
|
||||||
|
|
||||||
|
spinlock_acquire(&socket->lock);
|
||||||
|
|
||||||
|
if(socket->state != SOCKET_STATE_CONNECTED){
|
||||||
|
*error = ENOTCONN;
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(;;){
|
||||||
|
|
||||||
|
arch_interrupt_disable();
|
||||||
|
|
||||||
|
readc = ringbuffer_read(&socket->buffer, buff, len);
|
||||||
|
|
||||||
|
if(readc > 0){
|
||||||
|
event_signal(&socket->dataevent, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
spinlock_release(&socket->lock);
|
||||||
|
|
||||||
|
if(event_wait(&socket->dataevent, true)){
|
||||||
|
spinlock_acquire(&socket->lock);
|
||||||
|
readc = -1;
|
||||||
|
*error = EINTR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
spinlock_acquire(&socket->lock);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*error = 0;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
spinlock_release(&socket->lock);
|
||||||
|
|
||||||
|
return readc;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user