From 6ab4a280d530214310daab362bd87c4888a32a16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 21 Dec 2014 21:33:43 -0500 Subject: [PATCH] lib/socket: replace `NativeSocketAcceptResult` by a Nit class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/socket/socket_c.nit | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/socket/socket_c.nit b/lib/socket/socket_c.nit index 000e9f7..df55638 100644 --- a/lib/socket/socket_c.nit +++ b/lib/socket/socket_c.nit @@ -29,10 +29,6 @@ in "C Header" `{ #include #include - typedef struct sockaccept_result { - struct sockaddr_in addr_in; - int s_desc; - } S_ACCEPT_RESULT; `} # Wrapper for the data structure PollFD used for polling on a socket @@ -189,28 +185,22 @@ extern class NativeSocket `{ int* `} return d; `} - fun accept: NativeSocketAcceptResult + fun accept: nullable SocketAcceptResult do var addrIn = new NativeSocketAddrIn var s = native_accept(addrIn) - return new NativeSocketAcceptResult(s, addrIn) + return new SocketAcceptResult(s, addrIn) end end -extern class NativeSocketAcceptResult `{ S_ACCEPT_RESULT* `} - new (socket: NativeSocket, addrIn: NativeSocketAddrIn) `{ - S_ACCEPT_RESULT *sar = NULL; - sar = malloc(sizeof(S_ACCEPT_RESULT)); - sar->s_desc = *socket; - sar->addr_in = *addrIn; - return sar; - `} - - fun socket: NativeSocket `{ return &recv->s_desc; `} +# Result of a call to `NativeSocket::accept` +class SocketAcceptResult - fun addrIn: NativeSocketAddrIn `{ return &recv->addr_in; `} + # Opened socket + var socket: NativeSocket - fun destroy `{ free(recv); `} + # Address of the remote client + var addr_in: NativeSocketAddrIn end extern class NativeSocketAddrIn `{ struct sockaddr_in* `} -- 1.7.9.5