diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-16 00:36:51 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-16 00:37:15 +0100 |
| commit | 5a16476cef25775801a828c01baf815514fd7966 (patch) | |
| tree | fbaf3887ac1e85a357afeaf03488f97f67f76a4e /plugins/bladesio1/connection.c | |
| parent | 8349bf45e9b19d83506e1bb52f2053a7976922e5 (diff) | |
| download | pcsxr-sio-tcp.tar.gz | |
WIP TCP/SIOsio-tcp
Diffstat (limited to 'plugins/bladesio1/connection.c')
| -rw-r--r-- | plugins/bladesio1/connection.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/plugins/bladesio1/connection.c b/plugins/bladesio1/connection.c index c922f2f2..bf083e92 100644 --- a/plugins/bladesio1/connection.c +++ b/plugins/bladesio1/connection.c @@ -25,6 +25,7 @@ #if defined _WINDOWS #include <winsock2.h> #else +#include <fcntl.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> @@ -68,14 +69,14 @@ int connectionOpen() { #endif return -1; } - + setsockopt(serversock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_addr, sizeof(reuse_addr)); setsockopt(serversock, IPPROTO_TCP, TCP_NODELAY, (const char*)&one, sizeof(one)); memset(&address, 0, sizeof(address)); address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = settings.port; + address.sin_port = htons(settings.port); if(bind(serversock,(struct sockaddr*)&address,sizeof(address)) == -1) { #if defined _WINDOWS @@ -167,9 +168,16 @@ int connectionSend(u8 *pdata, s32 size) { int connectionRecv(u8 *pdata, s32 size) { int bytes = 0; - if(clientsock >= 0) - if((bytes = (int)recv(clientsock, (char*)pdata, size, 0)) < 0) + if(clientsock >= 0) { + int flags = fcntl(clientsock, F_GETFL, 0); + + fcntl(clientsock, F_SETFL, flags | O_NONBLOCK); + if((bytes = (int)recv(clientsock, (char*)pdata, size, 0)) < 0) { + fcntl(clientsock, F_SETFL, flags); return 0; + } + fcntl(clientsock, F_SETFL, flags); + } return bytes; } |
