Merge pull request #3 from JoinedSenses/patch-1
Transitional syntax update
This commit is contained in:
+43
-54
@@ -12,13 +12,15 @@ enum SocketType {
|
||||
SOCKET_RAW
|
||||
}
|
||||
|
||||
#define EMPTY_HOST 1
|
||||
#define NO_HOST 2
|
||||
#define CONNECT_ERROR 3
|
||||
#define SEND_ERROR 4
|
||||
#define BIND_ERROR 5
|
||||
#define RECV_ERROR 6
|
||||
#define LISTEN_ERROR 7
|
||||
enum {
|
||||
EMPTY_HOST = 1,
|
||||
NO_HOST,
|
||||
CONNECT_ERROR,
|
||||
SEND_ERROR,
|
||||
BIND_ERROR,
|
||||
RECV_ERROR,
|
||||
LISTEN_ERROR
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
@@ -200,10 +202,7 @@ enum SocketOption {
|
||||
* @param arg The argument set by SocketSetArg()
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketConnectCB
|
||||
{
|
||||
public(Handle:socket, any:arg)
|
||||
};
|
||||
typedef SocketConnectCB = function void (Handle socket, any arg);
|
||||
|
||||
/**
|
||||
* triggered if a listening socket received an incoming connection and is ready to be used
|
||||
@@ -216,10 +215,7 @@ funcenum SocketConnectCB
|
||||
* @param any arg The argument set by SocketSetArg() for the listen-socket
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketIncomingCB
|
||||
{
|
||||
public(Handle:socket, Handle:newSocket, const String:remoteIP[], remotePort, any:arg)
|
||||
};
|
||||
typedef SocketIncomingCB = function void (Handle socket, Handle newSocket, const char[] remoteIP, int remotePort, any arg);
|
||||
|
||||
/**
|
||||
* triggered if a socket receives data
|
||||
@@ -235,10 +231,7 @@ funcenum SocketIncomingCB
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketReceiveCB
|
||||
{
|
||||
public(Handle:socket, const String:receiveData[], const dataSize, any:arg)
|
||||
};
|
||||
typedef SocketReceiveCB = function void (Handle socket, const char[] receiveData, const int dataSize, any arg);
|
||||
|
||||
/**
|
||||
* called after a socket sent all items in its send queue successfully
|
||||
@@ -247,10 +240,7 @@ funcenum SocketReceiveCB
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketSendqueueEmptyCB
|
||||
{
|
||||
public(Handle:socket, any:arg)
|
||||
};
|
||||
typedef SocketSendqueueEmptyCB = function void (Handle socket, any arg);
|
||||
|
||||
/**
|
||||
* called if a socket has been properly disconnected by the remote side
|
||||
@@ -261,10 +251,7 @@ funcenum SocketSendqueueEmptyCB
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketDisconnectCB
|
||||
{
|
||||
public(Handle:socket, any:arg)
|
||||
};
|
||||
typedef SocketDisconnectCB = function void (Handle socket, any arg);
|
||||
|
||||
/**
|
||||
* called if an unrecoverable error occured, close the socket without an additional call to a disconnect callback
|
||||
@@ -277,11 +264,7 @@ funcenum SocketDisconnectCB
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
funcenum SocketErrorCB
|
||||
{
|
||||
public(Handle:socket, const errorType, const errorNum, any:arg)
|
||||
};
|
||||
|
||||
typedef SocketErrorCB = function void (Handle socket, const int errorType, const int errorNum, any arg);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/******************************************** natives ********************************************/
|
||||
@@ -294,7 +277,7 @@ funcenum SocketErrorCB
|
||||
* @param socket Socket handle to check
|
||||
* @return bool The connection status
|
||||
*/
|
||||
native bool:SocketIsConnected(Handle:socket);
|
||||
native bool SocketIsConnected(Handle socket);
|
||||
|
||||
|
||||
/**
|
||||
@@ -306,16 +289,17 @@ native bool:SocketIsConnected(Handle:socket);
|
||||
* @param SocketErrorCB efunc The error callback
|
||||
* @return Handle The socket handle. Returns INVALID_HANDLE on failure
|
||||
*/
|
||||
native Handle:SocketCreate(SocketType:protocol=SOCKET_TCP, SocketErrorCB:efunc);
|
||||
native Handle SocketCreate(SocketType protocol=SOCKET_TCP, SocketErrorCB efunc);
|
||||
|
||||
/**
|
||||
* Binds the socket to a local address
|
||||
*
|
||||
* @param Handle socket The handle of the socket to be used.␍ * @param String hostname The hostname (or IP) to bind the socket to.
|
||||
* @param Handle socket The handle of the socket to be used.
|
||||
* @param String hostname The hostname (or IP) to bind the socket to.
|
||||
* @param cell_t port The port to bind the socket to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
native bool:SocketBind(Handle:socket, const String:hostname[], port);
|
||||
native bool SocketBind(Handle socket, const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Connects a socket
|
||||
@@ -327,11 +311,12 @@ native bool:SocketBind(Handle:socket, const String:hostname[], port);
|
||||
* @param Handle socket The handle of the socket to be used.
|
||||
* @param SocketConnectCB cfunc The connect callback
|
||||
* @param SocketReceiveCB rfunc The receive callback
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback␍ * @param String hostname The hostname (or IP) to connect to.
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @param String hostname The hostname (or IP) to connect to.
|
||||
* @param cell_t port The port to connect to.
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketConnect(Handle:socket, SocketConnectCB:cfunc, SocketReceiveCB:rfunc, SocketDisconnectCB:dfunc, const String:hostname[], port);
|
||||
native void SocketConnect(Handle socket, SocketConnectCB cfunc, SocketReceiveCB rfunc, SocketDisconnectCB dfunc, const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Disconnects a socket
|
||||
@@ -341,7 +326,7 @@ native SocketConnect(Handle:socket, SocketConnectCB:cfunc, SocketReceiveCB:rfunc
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native bool:SocketDisconnect(Handle:socket);
|
||||
native bool SocketDisconnect(Handle socket);
|
||||
|
||||
/**
|
||||
* Makes a socket listen for incoming connections
|
||||
@@ -350,7 +335,7 @@ native bool:SocketDisconnect(Handle:socket);
|
||||
* @param SocketIncomingCB ifunc The callback for incoming connections
|
||||
* @return bool true on success
|
||||
*/
|
||||
native bool:SocketListen(Handle:socket, SocketIncomingCB:ifunc);
|
||||
native bool SocketListen(Handle socket, SocketIncomingCB ifunc);
|
||||
|
||||
/**
|
||||
* Sends data through the socket.
|
||||
@@ -364,10 +349,12 @@ native bool:SocketListen(Handle:socket, SocketIncomingCB:ifunc);
|
||||
*
|
||||
* @param Handle socket The handle of the socket to be used.
|
||||
* @param String data The data to send.
|
||||
* @noreturn␍ */
|
||||
native SocketSend(Handle:socket, const String:data[], size=-1);
|
||||
* @noreturn
|
||||
*/
|
||||
native void SocketSend(Handle socket, const char[] data, int size=-1);
|
||||
|
||||
/**␍ * Sends UDP data through the socket to a specific destination.
|
||||
/**
|
||||
* Sends UDP data through the socket to a specific destination.
|
||||
*
|
||||
* @note specify size for binary safe operation
|
||||
* @note if size is not specified the \0 terminator will not be included
|
||||
@@ -380,8 +367,9 @@ native SocketSend(Handle:socket, const String:data[], size=-1);
|
||||
* @param String data The data to send.
|
||||
* @param String hostname The hostname (or IP) to send to.
|
||||
* @param cell_t port The port to send to.
|
||||
* @noreturn␍ */
|
||||
native SocketSendTo(Handle:socket, const String:data[], size=-1, const String:hostname[], port);
|
||||
* @noreturn
|
||||
*/
|
||||
native void SocketSendTo(Handle socket, const char[] data, int size=-1, const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Set a socket option.
|
||||
@@ -389,8 +377,9 @@ native SocketSendTo(Handle:socket, const String:data[], size=-1, const String:ho
|
||||
* @param Handle socket The handle of the socket to be used. May be INVALID_HANDLE if not essential.
|
||||
* @param SocketOption option The option to modify (see enum SocketOption for details).
|
||||
* @param cellt_ value The value to set the option to.
|
||||
* @return cell_t 1 on success.␍ */
|
||||
native SocketSetOption(Handle:socket, SocketOption:option, value);
|
||||
* @return cell_t 1 on success.
|
||||
*/
|
||||
native int SocketSetOption(Handle socket, SocketOption option, int value);
|
||||
|
||||
|
||||
/**
|
||||
@@ -403,7 +392,7 @@ native SocketSetOption(Handle:socket, SocketOption:option, value);
|
||||
* @param SocketReceiveCB rfunc The receive callback
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketSetReceiveCallback(Handle:socket, SocketReceiveCB:rfunc);
|
||||
native void SocketSetReceiveCallback(Handle socket, SocketReceiveCB rfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket sent all items in its send queue
|
||||
@@ -416,7 +405,7 @@ native SocketSetReceiveCallback(Handle:socket, SocketReceiveCB:rfunc);
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketSetSendqueueEmptyCallback(Handle:socket, SocketSendqueueEmptyCB:sfunc);
|
||||
native void SocketSetSendqueueEmptyCallback(Handle socket, SocketSendqueueEmptyCB sfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket was properly disconnected by the remote side
|
||||
@@ -428,7 +417,7 @@ native SocketSetSendqueueEmptyCallback(Handle:socket, SocketSendqueueEmptyCB:sfu
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketSetDisconnectCallback(Handle:socket, SocketDisconnectCB:dfunc);
|
||||
native void SocketSetDisconnectCallback(Handle socket, SocketDisconnectCB dfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket triggered an error
|
||||
@@ -440,7 +429,7 @@ native SocketSetDisconnectCallback(Handle:socket, SocketDisconnectCB:dfunc);
|
||||
* @param SocketErrorCB efunc The error callback
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketSetErrorCallback(Handle:socket, SocketErrorCB:efunc);
|
||||
native void SocketSetErrorCallback(Handle socket, SocketErrorCB efunc);
|
||||
|
||||
|
||||
/**
|
||||
@@ -450,7 +439,7 @@ native SocketSetErrorCallback(Handle:socket, SocketErrorCB:efunc);
|
||||
* @param any arg The argument to set
|
||||
* @noreturn
|
||||
*/
|
||||
native SocketSetArg(Handle:socket, any:arg);
|
||||
native void SocketSetArg(Handle socket, any arg);
|
||||
|
||||
/**
|
||||
* Retrieve the local system's hostname as the command "hostname" does.
|
||||
@@ -460,12 +449,12 @@ native SocketSetArg(Handle:socket, any:arg);
|
||||
*
|
||||
* @return 1 on success
|
||||
*/
|
||||
native SocketGetHostName(String:dest[], destLen);
|
||||
native int SocketGetHostName(char[] dest, int destLen);
|
||||
|
||||
/**
|
||||
* _________________Do not edit below this line!_______________________
|
||||
*/
|
||||
public Extension:__ext_smsock =
|
||||
public Extension __ext_smsock =
|
||||
{
|
||||
name = "Socket",
|
||||
file = "socket.ext",
|
||||
|
||||
Reference in New Issue
Block a user