55
66enum SocketType {
77 SOCKET_TCP = 1 ,
8- SOCKET_UDP
8+ SOCKET_UDP ,
9+ SOCKET_UNIX
910}
1011
1112enum SocketErrorType {
@@ -36,13 +37,13 @@ enum SocketOption {
3637 SocketSendTimeout , // SO_SNDTIMEO (ms, 0 = disabled)
3738 DebugMode , // Enable debug logging
3839 SocketConnectTimeout , // Connect timeout (ms, 0 = disabled, TCP only)
39- SocketAutoClose // Auto close handle on disconnect/error (0 = disabled, 1 = enabled)
40+ SocketAutoFreeHandle // Auto close handle on disconnect/error (0 = disabled, 1 = enabled)
4041}
4142
4243/* *
4344 * Callback for connection established
4445 *
45- * @note TCP: Called when connection to remote host is established
46+ * @note TCP/Unix : Called when connection to remote host is established
4647 * @note UDP: Called when Connect() hostname resolution completes (UDP is connectionless)
4748 *
4849 * @param socket Socket handle
@@ -53,36 +54,36 @@ typedef SocketConnectCallback = function void (Socket socket, any data);
5354/* *
5455 * Callback for incoming connection on listening socket
5556 *
56- * @note TCP only : Called when a new client connects to a listening socket
57+ * @note TCP/Unix : Called when a new client connects to a listening socket
5758 * @note UDP: Not applicable (UDP is connectionless, use ReceiveCallback instead)
5859 *
5960 * @param socket Listening socket handle
6061 * @param newSocket New client socket handle
61- * @param remoteIP Client IP address
62- * @param remotePort Client port
62+ * @param remoteIP Client IP address (Unix: socket path)
63+ * @param remotePort Client port (Unix: 0)
6364 * @param data User data passed to SetIncomingCallback
6465 */
6566typedef SocketIncomingCallback = function void (Socket socket , Socket newSocket , const char [] remoteIP , int remotePort , any data );
6667
6768/* *
6869 * Callback for data received
6970 *
70- * @note TCP: Called when data is received from connected peer
71+ * @note TCP/Unix : Called when data is received from connected peer
7172 * @note UDP: Called when data is received from any sender
7273 *
7374 * @param socket Socket handle
7475 * @param buffer Received data (null-terminated)
7576 * @param size Data length (excluding null terminator)
76- * @param senderIP Sender IP address (UDP only, empty for TCP )
77- * @param senderPort Sender port (UDP only, 0 for TCP )
77+ * @param senderIP Sender IP address (TCP: remote peer, UDP: packet sender, Unix: empty )
78+ * @param senderPort Sender port (Unix: 0 )
7879 * @param data User data passed to SetReceiveCallback
7980 */
8081typedef SocketReceiveCallback = function void (Socket socket , const char [] buffer , const int size , const char [] senderIP , int senderPort , any data );
8182
8283/* *
8384 * Callback for remote disconnection
8485 *
85- * @note TCP only : Called when remote peer closes the connection
86+ * @note TCP/Unix : Called when remote peer closes the connection
8687 * @note UDP: Not applicable (UDP is connectionless)
8788 *
8889 * @param socket Socket handle
@@ -93,26 +94,26 @@ typedef SocketDisconnectCallback = function void (Socket socket, any data);
9394/* *
9495 * Callback for socket error
9596 *
96- * @param socket Socket handle
97- * @param errorType Error type (SocketErrorType)
98- * @param errorNum System errno
99- * @param data User data passed to SetErrorCallback
97+ * @param socket Socket handle
98+ * @param errorType Error type (SocketErrorType)
99+ * @param errorMsg Error message string
100+ * @param data User data passed to SetErrorCallback
100101 */
101- typedef SocketErrorCallback = function void (Socket socket , const int errorType , const int errorNum , any data );
102+ typedef SocketErrorCallback = function void (Socket socket , const int errorType , const char [] errorMsg , any data );
102103
103104/* *
104105 * Callback for listen ready
105106 *
106- * @note Called when Listen() completes and socket is ready to accept connections (TCP) or receive data (UDP)
107+ * @note Called when Listen() completes and socket is ready to accept connections (TCP/Unix ) or receive data (UDP)
107108 *
108109 * @param socket Socket handle
109- * @param localIP Local bound IP address
110- * @param localPort Local bound port
110+ * @param localIP Local bound IP address (Unix: socket path)
111+ * @param localPort Local bound port (Unix: 0)
111112 * @param data User data passed to SetListenCallback
112113 */
113114typedef SocketListenCallback = function void (Socket socket , const char [] localIP , int localPort , any data );
114115
115- // Socket methodmap for TCP/UDP communication
116+ // Socket methodmap for TCP/UDP/Unix communication
116117methodmap Socket < Handle {
117118 /* *
118119 * Creates a new socket
@@ -136,9 +137,10 @@ methodmap Socket < Handle {
136137 *
137138 * @note TCP: Establishes a connection to the remote host
138139 * @note UDP: Sets default destination for Send() (no actual connection)
140+ * @note Unix: Connects to the specified socket path (port is ignored)
139141 *
140- * @param host Remote IP or hostname
141- * @param port Remote port
142+ * @param host Remote IP or hostname (Unix: socket path)
143+ * @param port Remote port (Unix: ignored)
142144 */
143145 public native void Connect (const char [] host , int port );
144146
@@ -153,16 +155,16 @@ methodmap Socket < Handle {
153155 * Forcefully closes TCP connection with RST (TCP only)
154156 *
155157 * @note Immediately terminates connection without TIME_WAIT state
156- * @note Only works for TCP sockets, returns false for UDP
158+ * @note Only works for TCP sockets, returns false for UDP/Unix
157159 *
158160 * @return True on success
159161 */
160162 public native bool CloseReset ();
161163
162164 /* *
163- * Starts listening for connections (TCP) or receiving data (UDP)
165+ * Starts listening for connections (TCP/Unix ) or receiving data (UDP)
164166 *
165- * @note TCP: Starts accepting incoming connections (requires SetIncomingCallback)
167+ * @note TCP/Unix : Starts accepting incoming connections (requires SetIncomingCallback)
166168 * @note UDP: Starts receiving data (use SetReceiveCallback)
167169 *
168170 * @return True on success
@@ -172,7 +174,7 @@ methodmap Socket < Handle {
172174 /* *
173175 * Sends data
174176 *
175- * @note TCP: Sends to connected peer
177+ * @note TCP/Unix : Sends to connected peer
176178 * @note UDP: Requires prior Connect() call to set destination
177179 *
178180 * @param data Data to send
@@ -195,7 +197,7 @@ methodmap Socket < Handle {
195197 *
196198 * @param option Option to set
197199 * @param value Option value
198- * @return True on success false on failure
200+ * @return True on success, false on failure
199201 */
200202 public native bool SetOption (SocketOption option , int value );
201203
@@ -232,9 +234,9 @@ methodmap Socket < Handle {
232234 public native void SetConnectCallback (SocketConnectCallback callback , any data = 0 );
233235
234236 /* *
235- * Sets incoming connection callback (TCP only)
237+ * Sets incoming connection callback (TCP/Unix only)
236238 *
237- * @note Required for TCP server mode. Not applicable for UDP.
239+ * @note Required for TCP/Unix server mode. Not applicable for UDP.
238240 *
239241 * @param callback Callback function
240242 * @param data User data passed to callback
@@ -256,7 +258,7 @@ methodmap Socket < Handle {
256258 *
257259 * @param buffer Destination buffer
258260 * @param maxLength Buffer size
259- * @return True on success false on failure
261+ * @return True on success, false on failure
260262 */
261263 public static native bool GetHostName (char [] buffer , int maxLength );
262264
@@ -268,7 +270,7 @@ methodmap Socket < Handle {
268270 *
269271 * @param buffer Destination buffer
270272 * @param maxLength Buffer size
271- * @return True on success false on failure
273+ * @return True on success, false on failure
272274 */
273275 public native bool GetLocalAddress (char [] buffer , int maxLength );
274276
@@ -283,7 +285,10 @@ methodmap Socket < Handle {
283285 public native int GetLocalPort ();
284286
285287 /* *
286- * Whether socket is connected
288+ * Whether socket is connected/listening
289+ *
290+ * @note TCP/Unix: True if connected to peer or listening for connections
291+ * @note UDP: True if socket is initialized
287292 */
288293 property bool Connected {
289294 public native get ();
0 commit comments