#include <dolphin/ip.h>
typedef BOOL (* TCPListenCallback )(TCPInfo* info, s32 result);
typedef struct IPSocket
{
u8 len; // IP_SOCKLEN
u16 family; // IP_INET
u16 port;
u8 addr[IP_ALEN];
} IPSocket;
s32 TCPListen( TCPInfo* listening,
IPSocket* local, IPSocket* remote,
TCPListenCallback callback, s32* result );
TCPListen() puts listening
in listening mode. Then listening keeps
waiting for a connection request until it is closed. If the local socket has not
been specified with TCPBind(), an ephemeral local socket will be automatically
chosen between 1024 and 5000.
Every time a connection request is arrived, the library run-time calls the
optional callback function. If the callback
function returns FALSE, the connection request is rejected. To
accept the connection request, the callback
function must return non-zero value. If no callback function is specified, every
connection request will be accepted.
To
establish a connection, another TCPInfo must have been queued with
TCPAcceptAsync() before returning from the listen callback
function.
TCPAcceptAsync() can be called inside the callback. If there
is no accepting
TCPInfo when a connection request is arrived, the
library run-time silently ignores the request. Multiple TCPInfo can be queued to accept
multiple connection requests with
TCPAcceptAsync().
Note: If there is no listening TCPInfo to the specified local socket, the
library run-time explicitly resets the connection request by sending RST segment
to the other end (rather than simply
drops the request).
Send and receive buffers: For listening TCPInfo,
neither send buffer nor receive buffer is necessary.
listening |
Pointer to bound, unconnected TCPInfo. |
local |
Optional pointer to IPSocket that receives the local socket
of the received connection request. |
remote |
Optional pointer to IPSocket that receives the remote socket
of the received connection request. |
callback |
Optional. Informed when a connection request is arrived (before connection is established). |
result |
Optional pointer to s32 that receives the function result.
If TCPListen() is succeeded, the value *result
is set to IP_ERR_NONE and is never
set to IP_ERR_BUSY. |
IP_ERR_NONE |
Succeeded. |
IP_ERR_EXIST |
Specified socket is already in use. |
IP_ERR_INVALID |
listening is not a valid TCPInfo. |
IP_ERR_INS_RESOURCES |
Used up ephemeral local ports. |
IP_ERR_NONE |
A new connection request is arrived. |