Description | Hierarchy | Fields | Methods | Properties |
type unaSocks = class(unaObject)
This class is used to create server and client sockets and manage the connections.
constructor create(threadsInPool: unsigned = 4 ); |
|
destructor Destroy(); override; |
|
function activate(id: tConID): bool; |
|
function closeThread(id: tConID; timeout: tTimeout = 2700): bool; |
|
function createConnection(const host, port: string; protocol: int = IPPROTO_TCP; activate: bool = true; const bindToIP: string = '0.0.0.0'; const bindToPort: string = '0' ): tConID; |
|
function createServer(const port: string; protocol: int = IPPROTO_TCP; activate: bool = true; backlog: int = SOMAXCONN; udpConnectionTimeout: tTimeout = c_defUdpConnTimeout; const bindToIP: string = '0.0.0.0' ): tConID; |
|
function enter(ro: bool; timeout: tTimeout = tTimeout(INFINITE)): bool; |
|
function getConnection(id: tConID; connId: tConID; timeout: tTimeout = 2000; needAcquire: bool = true): unaSocksConnection; |
|
function getRemoteHostAddr(id, connId: tConID): pSockAddrIn; |
|
function getRemoteHostInfo(addr: pSockAddrIn; out ip, port: string): bool; overload; |
|
function getRemoteHostInfo(id, connId: tConID; out ip, port: string): bool; overload; |
|
function getRemoteHostInfoEx(id, connId: tConID; out ip, port: string; out proto: int): bool; |
|
function getSocketError(id: tConID; needLock: bool = true): int; |
|
function getThreadByID(id: tConID; timeout: tTimeout = 1000): unaSocksThread; |
|
function getThreadSocket(id: tConID): unaSocket; |
|
function isActive(id: tConID): bool; |
|
function okToWrite(id, connId: tConID; timeout: tTimeout = 100; noCheckState: bool = false): bool; |
|
function removeConnection(id: tConID; connId: tConID): bool; |
|
function sendData(id: tConID; data: pointer; size: uint; connId: tConID; out asynch: bool; noCheck: bool = false; timeout: tTimeout = 500): uint; |
|
procedure clear(clearServers: bool = false; clearClients: bool = false); |
|
procedure leaveRO(); |
|
procedure leaveWO(); |
|
procedure setPoolSize(threadsInPool: unsigned); |
|
procedure event(event: unaSocketEvent; id, connId: tConID; data: pointer = nil; size: uint = 0); virtual; |
property onEvent: unaSocksOnEventEvent read f_onEvent write f_onEvent; |
constructor create(threadsInPool: unsigned = 4 ); |
|
Creates socks object.
Parameters
|
destructor Destroy(); override; |
|
Destroys socks object. |
function activate(id: tConID): bool; |
|
Activate a thread (start server or connect client).
Parameters
ReturnsTrue if thread was started successfully. |
function closeThread(id: tConID; timeout: tTimeout = 2700): bool; |
|
Closes and removes all connection for specified thread. Also stops the thread and makes it available for new connections.
Parameters
ReturnsTrue if operation was successfull. |
function createConnection(const host, port: string; protocol: int = IPPROTO_TCP; activate: bool = true; const bindToIP: string = '0.0.0.0'; const bindToPort: string = '0' ): tConID; |
|
Creates new client socket. Returns thread id which will handle events for this client connection or 0 if some error occured.
Parameters
ReturnsThread id or 0 if some error occured. |
function createServer(const port: string; protocol: int = IPPROTO_TCP; activate: bool = true; backlog: int = SOMAXCONN; udpConnectionTimeout: tTimeout = c_defUdpConnTimeout; const bindToIP: string = '0.0.0.0' ): tConID; |
|
Creates new server socket. Returns thread id which will handle connections for this socket or 0 if some error occur.
Parameters
ReturnsThread id or 0 if some error occured. |
function enter(ro: bool; timeout: tTimeout = tTimeout(INFINITE)): bool; |
|
Locks socks object. Parameters
|
function getConnection(id: tConID; connId: tConID; timeout: tTimeout = 2000; needAcquire: bool = true): unaSocksConnection; |
|
Returns specified connection. WARNING! If needAcquire was Parameters
ReturnsConnection object or nil. |
function getRemoteHostAddr(id, connId: tConID): pSockAddrIn; |
|
Returns remote address for connection.
Parameters
ReturnsPointer to address record or nil. |
function getRemoteHostInfo(addr: pSockAddrIn; out ip, port: string): bool; overload; |
|
Converts address record into IP and port.
Parameters
ReturnsTrue if function was successfull. |
function getRemoteHostInfo(id, connId: tConID; out ip, port: string): bool; overload; |
|
Returns remote IP and port for connection.
Parameters
ReturnsTrue if function was successfull. |
function getRemoteHostInfoEx(id, connId: tConID; out ip, port: string; out proto: int): bool; |
|
Returns remote IP, port and proto for connection.
Parameters
ReturnsTrue if function was successfull. |
function getSocketError(id: tConID; needLock: bool = true): int; |
|
Returns socket error for a thread.
Parameters
ReturnsError code. |
function getThreadByID(id: tConID; timeout: tTimeout = 1000): unaSocksThread; |
|
Returns thread object.
Parameters
ReturnsThread object or nil. |
function getThreadSocket(id: tConID): unaSocket; |
|
Returns socket object assigned to a thread.
Parameters
ReturnsSocket object or nil. |
function isActive(id: tConID): bool; |
|
Returns thread active state. ReturnsTrue if thread is active (server is listening, client is connected). |
function okToWrite(id, connId: tConID; timeout: tTimeout = 100; noCheckState: bool = false): bool; |
|
Returns true if it seems that we can send data to remote side over specified connection.
Parameters
ReturnsTrue if data can be send. |
function removeConnection(id: tConID; connId: tConID): bool; |
|
Closes and removes specified connection. If thread has no more connections, closes it as well.
Parameters
ReturnsTrue if connection was closed. |
function sendData(id: tConID; data: pointer; size: uint; connId: tConID; out asynch: bool; noCheck: bool = false; timeout: tTimeout = 500): uint; |
|
Sends data to remote side over specified connection.
Parameters
Returns0 if data was sent successfully, or specific WSA error otherwise. |
procedure clear(clearServers: bool = false; clearClients: bool = false); |
|
Closes all client or server (or both) threads.
Parameters
|
procedure leaveRO(); |
|
Unlocks socks object. |
procedure leaveWO(); |
|
Unlocks socks object. |
procedure setPoolSize(threadsInPool: unsigned); |
|
Sets new pool size. Parameters
|
procedure event(event: unaSocketEvent; id, connId: tConID; data: pointer = nil; size: uint = 0); virtual; |
|
This virtual method is called every time new sockets event occur.
Parameters
|
property onEvent: unaSocksOnEventEvent read f_onEvent write f_onEvent; |
|
This event is fired every time new sockets event occurs. Refer to .event() method for more information. |
(c) 2012 Lake of Soft