Fix multiplayer not working

This commit is contained in:
UnknownShadow200 2021-05-23 15:27:42 +10:00
parent 3e828d09af
commit 355f35c719
2 changed files with 8 additions and 10 deletions

View File

@ -283,7 +283,9 @@ cc_result Socket_GetError(cc_socket s, cc_result* result) {
cc_result Socket_Connect(cc_socket s, const cc_string* ip, int port) { cc_result Socket_Connect(cc_socket s, const cc_string* ip, int port) {
char addr[NATIVE_STR_LEN]; char addr[NATIVE_STR_LEN];
Platform_EncodeUtf8(addr, ip); Platform_EncodeUtf8(addr, ip);
return interop_SocketConnect(s, addr, port);
/* returned result is negative for error */
return -interop_SocketConnect(s, addr, port);
} }
cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) { cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) {

View File

@ -203,17 +203,13 @@ mergeInto(LibraryManager.library, {
getPending:function(fd) { getPending:function(fd) {
var sock = this.sockets[fd]; var sock = this.sockets[fd];
if (!sock) return this.EBADF; if (!sock) return this.EBADF;
var bytes = 0; return sock.recv_queue.length;
if (sock.recv_queue.length) {
bytes = sock.recv_queue[0].data.length;
}
return bytes;
}, },
getError:function(fd) { getError:function(fd) {
var sock = this.sockets[fd]; var sock = this.sockets[fd];
if (!sock) return this.EBADF; if (!sock) return this.EBADF;
return sock.error || 0; return sock.error || 0;
}, },
close:function(fd) { close:function(fd) {
@ -277,8 +273,8 @@ mergeInto(LibraryManager.library, {
sock.recv_queue.unshift(packet); sock.recv_queue.unshift(packet);
} }
HEAPU8.set(msg.buffer, dst); HEAPU8.set(msg, dst);
return msg.buffer.byteLength; return msg.byteLength;
} }
}; };
}, },