Raised This Month: $52 Target: $400
 13% 

Module: Threaded Sockets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 05-15-2015 , 14:30   Module: Threaded Sockets
Reply With Quote #1

Threaded Sockets - v1.1(1 June, 2016)

Description:
This module is a modification of Default Amxx Sockets module, implementing option for performing threaded socket operations. This Module also include changes done in Sockets2(Bugsy) and Socket_hz in a threaded mode. This module eliminates looping, hidden looping, entity thinks in plugin as well as in the main thread.
Natives:
A list of all natives.
PHP Code:
native socket_open(const _hostname[], _port_protocol SOCKET_TCP, &_error);
native socket_close(_socket);
native socket_recv(_socket_data[], _length);
native socket_send(_socket, const _data[], _length);
native socket_send2(_socket, const _data[], _length);
native socket_change(_socket_timeout=100000);

/**
 * Threaded Natives
*/

native socket_create_t();
native socket_open_t( const iThreadHandle, const szHostname[], const port, const protocol, const CallBackHandler[] );
native socket_send_t( const iThreadHandle, const szData[], const iDataLen, const CallBackHandler[] );
native socket_recv_t( const iThreadHandle, const CallBackHandler[], const iRecvDataLen );
native socket_close_t( const iThreadHandle, const CallBackHandler[] );
native socket_destroy_t( const iThreadHandle );
native socket_get_last_error_t( const iThreadHandle );
native socket_listen_t( const iThreadHandle, const szHostname[], const port, const protocol, const CallBackHandler[] );
native socket_accept_t( const iThreadHandle, const CallBackHandler[] );
native socket_get_sd_t( const iThreadHandle );
native socket_set_sd_t( const iThreadHandle, const iSocketDescriptor ); 
1. socket_create_t()
PHP Code:
/**
 * Spawns a new Thread.
 * returns a ThreadHandle (positive) or negative on error (Could not create a Thread).
 * The ThreadHandle is to be used for all other *_t natives.
*/
native socket_create_t(); 
2. socket_open_t()
PHP Code:
/** 
 * Sets the passed data to thread object and puts the Thread is STATE_CONNECT which 
 * opens a new connection to hostname:port via protocol (either SOCKET_TCP or SOCKET_UDP).
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param szHostname                 A string containing ip or domain name to be connected to.
 * @param port                       An integer representing the port to which the connection is to be made.
 * @param protocol                   An integer specifying the protocol, 
 *                                        @arg @c SOCKET_TCP for TCP.
 *                                        @arg @c SOCKET_UDP for UDP.
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn )
 * @param iThreadState               STATE_CONNECT in this case.
 * @param iReturn                    0 On Success and Negative for Error (Described above).
 *                                   Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * 
 * @note ThreadState is set to STATE_IDLE before CallBack. 
 *
 * @return                           0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC).
*/
native socket_open_t( const iThreadHandle, const szHostname[], const port, const protocol, const CallBackHandler[] );/ 
3. socket_send_t()
PHP Code:
/**
 * Set the required data to Thread object, Set its state to STATE_SEND to send data via a socket .
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param szData                     A String containing the data to be sent, can contain null characters.
 * @param iDataLen                   Length of the szData array.
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn )
 * @param iThreadState               STATE_SEND in this case.
 * @param iReturn                    Positive on Success (Length of the data sent) and SOCKET_ERROR on error.
 *                                   Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * 
 * @note ThreadState is set to STATE_IDLE before CallBack. 
 * 
 * @return                           0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC).
*/
native socket_send_t( const iThreadHandle, const szData[], const iDataLen, const CallBackHandler[] ); 
4. socket_recv_t()
PHP Code:
/**
 * Set the required data to Thread object, Set its state to STATE_READ to recieve data from a socket.
 * 
 * @param iThreadHandle            A ThreadHandle returned by socket_create_t().
 * @param iRecvDataLen                Length of the data that must be recieved at a time.
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn, szRecvData[], iRecvDataLen )
 * @param iThreadState                STATE_READ in this case.
 * @param iReturn                 Positive on successful read (Length of the data actually read), 0 on Connection close and
 *                                 SOCKET_ERROR on error. Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * @param szRecvData[]                A null-terminated string containing the recieved data.
 * @param iRecvDataLen                The length requested by plugin to be read. Actual RecvDataLen may be less than requested. 
 *                                 This is the same length passed to the native.
 * @return                        If a number greater than 0 is returned by callback, iRecvDataLen is dynamically set to that number.
 *
 * @note ThreadState is set to STATE_IDLE, only when the connection is closed or on error, before CallBack. Therefore the CallBack may
 * be called more than one time passing blocks of szRecvData with length less than or equeal to iRecvDataLen.
 * 
 * @return                         0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC)
*/
native socket_recv_t( const iThreadHandle, const CallBackHandler[], const iRecvDataLen ); 
5. socket_close_t()
PHP Code:
/**
 * Close the Socket.
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn )
 * @param iThreadState               STATE_DISCONNECT in this case.
 * @param iReturn                    0 on successful close and SOCKET_ERROR on error.
 *                                   Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * 
 * @note ThreadState is set to STATE_IDLE before CallBack. 
 * @note This function only closes the Socket not the thread. So that the thread can be reused for another new socket communication.
 * 
 * @return                           0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC)
 * 
*/
native socket_close_t( const iThreadHandle, const CallBackHandler[] ); 
6. socket_destroy_t()
PHP Code:
/**
 * Destroyes the Thread aswell as the Socket by putting the thread is STATE_DESTROY. 
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * 
 * @note After destroying no futher references should be made with iThreadHandle, Doing so may result is SEGSIGV faults.
 * The iThreadHandle must be a vaild iThreadHandle, if not, again may result in SEGSIGV faults. So you have to be more careful
 * while using this function. Best way to use this function is,
 * 
 * Example :
 * if( g_iThreadHandle )
 *                     socket_destroy_t(g_iThreadHandle);
 * 
 * @return                           0
*/
native socket_destroy_t( const iThreadHandle ); 
7. socket_get_last_error_t()
PHP Code:
/**
 * Get last error from the OS Socket APIs.
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @return                           ErrorCode of the error.
*/
native socket_get_last_error_t( const iThreadHandle ); 
List of All ErrorCodes returned by this native:
On Windows

On Linux

8. socket_listen_t()
PHP Code:
/** 
 * Sets the passed data to thread object and puts the Thread in STATE_LISTEN which 
 * puts the socket is listen mode for a new connection to localip:port via protocol (either SOCKET_TCP or SOCKET_UDP).
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param szHostname                 A string containing ip or domain name to be connected to.
 * @param port                       An integer representing the port to which the connection is to be made.
 * @param protocol                   An integer specifying the protocol, 
 *                                        @arg @c SOCKET_TCP for TCP.
 *                                        @arg @c SOCKET_UDP for UDP.
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn )
 * @param iThreadState               STATE_LISTEN in this case.
 * @param iReturn                    0 On Success and Negative for Error (Described above).
 *                                   Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * 
 * @note ThreadState is set to STATE_IDLE before CallBack. 
 *
 * @return                           0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC)
*/
native socket_listen_t( const iThreadHandle, const szHostname[], const port, const protocol, const CallBackHandler[] ); 
9. socket_accept_t()
PHP Code:
/**
 * Registers the CallBackHandler and puts the Thread in STATE_ACCEPT state which
 * will try to accept ONE connection. Therefore, if one needs to accept more connections, this function must again
 * be called in CallBackHandler. The maximum length of the queue of pending connections is 10. 11th client will
 * recieve 'Connection Refused' error.
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param CallBackHandler            A string containing name of a Public function to be registered as callback.
 * 
 * @fn public CallBackHandler( iThreadState, iReturn, szClientAddr[], iClientAddrLen, clientport )
 * @param iThreadState               STATE_ACCEPT in this case.
 * @param iReturn                    SocketDescriptor on Success and SOCKET_ERROR on error.
 *                                   Call socket_get_last_error_t() to get more specific errorno from OS APIs.
 * @param szClientAddr               On Success, This is a string containing the ip of the new accepted client.
 * @param iClientAddrLen             On Success, This is the length of ClientAddr.
 * @param clientport                 On Success, This will represent the clientport.
 * 
 * @note ThreadState is set to STATE_IDLE, after accepting on client connection, before CallBack. 
 * 
 * @return                           0 on Success, negative on error (SOCKET_ERROR on invalid iThreadHandle and SOCKET_COULDNOT_FIND_CLLBKFUNC).
*/
native socket_accept_t( const iThreadHandle, const CallBackHandler[] ); 
10. socket_get_sd_t()
PHP Code:
/**
 * Get SocketDescriptor of the iThreadHandle passed.
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * 
 * @return                           Returns iSocketDescriptor of iThreadHandle.
*/
native socket_get_sd_t( const iThreadHandle ); 
11. socket_set_sd_t()
PHP Code:
/**
 * Set SocketDescriptor of the iThreadHandle passed.
 * 
 * @param iThreadHandle              A ThreadHandle returned by socket_create_t().
 * @param iSocketDescriptor          A SocketDescriptor that must be used by the iThreadHandle obj.
 * 
 * @return                           0
*/
native socket_set_sd_t( const iThreadHandle, const iSocketDescriptor ); 
Examples:
Example 1 : Sockets for Downloading a HTTP page.
PHP Code:
#include <amxmodx>
#include <sockets>

new g_iThreadHandle;
new 
pCvar_HostNamepCvar_Page;
new 
g_File;

public 
plugin_init()
{
    
register_plugin"Threaded Sockets Testing""1.0""Shooting King" );
    
register_concmd"say /test" "TestCmd" ); 
    
register_concmd"/test" "TestCmd" );
    
    
pCvar_HostName register_cvar"sk_ts_hostname""example.com" );
    
pCvar_Page register_cvar"sk_ts_page""/" );
}

public 
TestCmd()
{
    
g_iThreadHandle socket_create_t();
    
    new 
szHostName[64];
    
get_pcvar_stringpCvar_HostNameszHostName64 );
    
    if((
socket_open_t(g_iThreadHandleszHostName80SOCKET_TCP"CBOpenSocket")) < )
    {
        
log_amx"ERROR: Could not open Socket." );
        return;
    }
    
log_amx"Trying to open connection..." );
}

public 
CBOpenSocketiThreadStateiReturn )
{
    if( 
iReturn )
    {
        
log_amx"ERROR: Could not open Socket. Error[%d] : %d"iReturnsocket_get_last_error_t(g_iThreadHandle) );
    }
    else
    {        
        new 
szPacket[128]; 
        new 
szHostName[64], szPage[64];
        
get_pcvar_stringpCvar_HostNameszHostName64 );
        
get_pcvar_stringpCvar_PageszPage64 );
        
        
formatexszPacket127"GET %s HTTP/1.1^r^nHost: %s^r^n^r^n"szPageszHostName );
        
        
log_amx"Socket Opened. Trying to send Data..." );
        if((
socket_send_tg_iThreadHandleszPacketsizeof(szPacket), "CBSendSocket")) < )
        {
            
log_amx"ERROR: Could not Send data." );
        }
    }
}

public 
CBSendSocketiThreadStateiReturn )
{
    if( 
iReturn )
    {
        
log_amx"ERROR: Error Sending Data. Error[%d] : %d"iReturnsocket_get_last_error_t(g_iThreadHandle) );
    }
    else
    {
        
log_amx"Socket Opened. Data Sent. Trying to receive Data..." );
        if( (
socket_recv_tg_iThreadHandle"CBRecvSocket"64 )) < )
        {
            
log_amx"ERROR: Could receive data." );
        }
        
g_File fopen"test.html""w" );
    }
}

public 
CBRecvSocketiThreadStateiReturnszRecvData[], iRecvDataLen )
{
    if( 
iReturn == )
    {
        
log_amx"Connection gracefully closed." );
        
socket_close_t(g_iThreadHandle"CBCloseSocket");
        
fcloseg_File );
    }
    else if( 
iReturn )
    {
        
log_amx"ERROR: Error while receiveing data. Error[%d] : %d"iReturnsocket_get_last_error_t(g_iThreadHandle) );
        
socket_close_t(g_iThreadHandle"CBCloseSocket");
    }
    else
    {
        
log_amx"Successfully Received Data[%d] : Received - %d "iRecvDataLenszRecvDatastrlen(szRecvData));
        
fprintfg_FileszRecvData );
    }
}

public 
CBCloseSocketiThreadStateiReturn )
{
    if( 
iReturn == )
    {
        
log_amx"Socket Closed. Destroying Thread." );
        
socket_destroy_t(g_iThreadHandle);
    }
    else
    {
        
log_amx"Error Closing socket.  Errno : %d"socket_get_last_error_t(g_iThreadHandle) );
    }

Example 2 : Listening and Accepting connections on specific IP and Port.
PHP Code:
#include <amxmodx>
#include <sockets>

new const szListenAddr[] = "192.168.2.2";
new const 
iListenPort 79;

new 
g_iThreadHandle 0g_ClientSThread 0;

public 
plugin_init()
{
    
register_plugin"Threaded Sockets (L/C) Testing""1.0""Shooting King" );
    
register_concmd"say /testla" "TestCmd" ); 
    
register_concmd"/testla" "TestCmd" );
}

public 
TestCmd()
{
    
g_iThreadHandle socket_create_t();
    
    if( 
socket_listen_t(g_iThreadHandleszListenAddriListenPortSOCKET_TCP"CBSocketListen" ) < )
    {
        
log_amx"Error: Could not listen on %s:%d"szListenAddriListenPort );
        return;
    }
    
log_amx"Trying to listen on %s:%d"szListenAddriListenPort );
}

public 
CBSocketListeniThreadState iReturn )
{
    if( 
iReturn )
    {
        
log_amx"Error: Could not listen on %s:%d. Error[%d] : %d"szListenAddriListenPortiReturn );
    }
    else
    {
        
log_amx"Listening on %s:%d. Waiting to accept connection ..."szListenAddriListenPort );
        if( 
socket_accept_tg_iThreadHandle"CBSocketAccept" ) < )
        {
            
log_amx"Error: Could not accept connection." );
        }
    }
}

public 
CBSocketAcceptiThreadStateiReturnszClientAddr[], iClientAddrLenclientport )
{
    if( 
iReturn )
    {
        
log_amx"Error: Could not accept connection. Error[%d] : %d"iReturnsocket_get_last_error_t(g_iThreadHandle) );
    }
    else
    {
        
log_amx"Accepted Connection from %s[%d]:%d"szClientAddriClientAddrLenclientport );
        
socket_accept_t(g_iThreadHandle"CBSocketAccept");
        
        
//iReturn is the new Client Socket.
        
g_ClientSThread socket_create_t();
        
socket_set_sd_tg_ClientSThreadiReturn );
        new 
szData[] = "Hello this is SK.";
        if( 
socket_send_tg_ClientSThreadszDatastrlen(szData), "CBClientSendHandler" ) < )
        {
            
log_amx"Error: Could not send data(%s) to client."szData );
        }
    }
}

public 
CBClientSendHandleriThreadStateiReturn )
{
    if( 
iReturn )
    {
        
log_amx"Data has been sent to client. Closing Client Socket ..." );
        
socket_close_t(g_ClientSThread"CBClientCloseSocket" );
    }
    else
    {
        
log_amx"Error: Could not send data(%s) to client. Error[%d] : %d"iReturnsocket_get_last_error_t(g_ClientSThread) );
    }
}

public 
CBClientCloseSocketiThreadStateiReturn )
{
    
socket_destroy_t(g_ClientSThread);
}

public 
plugin_end()
{
    if( 
g_iThreadHandle )
    {
        
socket_destroy_t(g_iThreadHandle);
    }

A Php-Client for testing the above plugin.

PHP Code:
<?php
error_reporting
(E_ALL);

echo 
"<h2>TCP Connection Tester</h2>\n";

$address '192.168.2.2';
$port 79;

/* Create a TCP/IP socket. */
$socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
if (
$socket === false
{
    echo 
"socket_create() failed: reason: " socket_strerror(socket_last_error()) . "<br/>";
}
else 
{
    echo 
"OK.<br/>";
}

echo 
"Attempting to connect to '$address' on port '$port'...";
$result socket_connect($socket$address$port);
if (
$result === false
{
    echo 
"socket_connect() failed.\nReason: ($result) " socket_strerror(socket_last_error($socket)) . "<br/>";

else 
{
    echo 
"OK.<br/>";
}

echo 
"Reading response:<br/><br/>";
while (
$out socket_read($socket2048)) 
{
    echo 
'<br/><b>'.$out.'</b><br/>';
}

echo 
"Closing socket...";
socket_close($socket);
echo 
"OK.<br/><br/>";
?>
For Developers:
How Module works ?
ThreadState Diagram:
A Thread spawned by module, in its lifetime, exists in one of the following ThreadStates. These states can be altered by plugins.
PHP Code:
// Thread states
enum
{
    
STATE_DESTROY,    
    
/* The Thread will destroy itself as well as the CThreadedSocketItem obj it is associated with */
    
STATE_CONNECT,    
    
/* The Thread will try to connect, Thread state is set to STATE_IDLE before CallBack */
    
STATE_DISCONNECT,
    
/* The Thread will disconnect the socket, Thread state is set to STATE_IDLE before CallBack */
    
STATE_READ,
    
/* The Thread will try to read data from the socket, Thread State is set to STATE_IDLE, if there is an error or if the connection is closed */
    
STATE_SEND,
    
/* The Thread will send data to the socket, Thread State is set to STATE_IDLE before CallBack */
    
STATE_LISTEN,
    
/* The Thread will set the socket to listen mode, Thread State is set to STATE_IDLE before CallBack */
    
STATE_ACCEPT,
    
/* The Thread will try to accept new connections, Thread State is set to STATE_IDLE, when a client is accepted, before CallBack */
    
STATE_IDLE
    
/* Idle state of the thread, thread does nothing except checking for change in ThreadState */
}; 
A diagram showing ThreadStates during lifetime of a Thread.

Class Diagram:
There are four main classes in this module. They are,
  • CSockets -
    This class is responsible for all low level socket operations.
  • CThreadedSockets -
    This class is a combination of Sockets and Threads. Setting thread states, thread operations like connect, open, listen, destroy etc are defined here. This Class also stores required data for these operations, acts as a bridge between Mainthread and Child(spawned) thread and makes the communications synchronous. For socket operations, this class implements/uses CSocket class.
  • CThreadedSocketItem -
    Inheriting all members from CThreadedSocket Class, This class makes CThreadedSocket as an Item for CThreadedSocketManager to save in its linked list.
  • CThreadedSocketManager -
    This Class maintains a double linked list of all the spawned Threads. If the spawned threads are not properly destroyed, this Class forcefully destroys the threads at AMXX_DETACH.

These classes are interlinked in a hierarchy as shown below,
How to debug ?
However perfect one tries to be, he cant be 100%. So, I don't give a guarantee that Module will work all the time. So, if you want to complain a bug, you have to specify the event at which it occurs or you can exactly point me to the code, where it crashed, by Debugging the module. I will tell you the most simple method to debug on linux as well as on windows.

On Windows,

I personally used Microsoft Visual Studio 2012 Just-In-Time debugger while making this module.
1. Download Debug Project of this Module.
2. Compile yourself the Project so that you can get the Symbol files (.pdbs).
3. Now Copy the output binary into HLDS and run it.
4. When HLDS crashes, you will get an option to debug.
5. When Just-In-Time debugger opens, it will show you the exception (It will be helpful if you even attach this Exception message with your bug report), Select "Break".
6. You will be pointed to the line at which crash has occurred, post this line, as well as the info from call stack window.
On Linux,

We have to use the good old gdb to debug the crash point.
1. Download gdb if you don't have it already.
for ubuntu you can use the following command,
Code:
sudo apt-get install libc6-dbg gdb
2. Edit the hlds_run as follows,
From ( Ln. 138 )
PHP Code:
    if test -"$PID_IN_PARAMS&& test -"$PID_FILE"then
        HL_CMD
="$HL $PARAMS -pidfile $PID_FILE"
    
else
        
HL_CMD="$HL $PARAMS"
    
fi 
To
PHP Code:
    if test -"$PID_IN_PARAMS&& test -"$PID_FILE"then
        HL_CMD
="$GDB --args $HL $PARAMS -pidfile $PID_FILE"
    
else
        
HL_CMD="$GDB --args $HL $PARAMS"
    
fi 
3. Download debug build version binary of this Module.
4. Now open hlds as
Code:
./hlds_run
5. You should be running with gdb and type the following cmds to run HLDS
Code:
run -game cstrike +map de_dust
with some additional parameters as you like.
6. Do whatever you want to reproduce the crash. After crashing you will be returned to gdb prompt. Type 'bt' or 'where' to get the call stack. Attach those with your bug report.
Now your bug report should contain:
0. Info about what you are trying to do as well as the code.
1. If possible, Exception Message.
2. If possible, Line at which the crash occurred.
3. List of CallStack frames.
4. Complete console log. (Since you are using debug version of Module, it will print some info on console as well)
TODO:
  • Nullify iThreadHandle variable in plugin on socket_destroy_t().
    I tried this but i don't know why it didn't work ._.
    PHP Code:
    static cell AMX_NATIVE_CALL socket_destroy_t(AMX *amxcell *params)  /* 1 param */
    {
        if( !
    params[1] )
            return -
    1;

        
    // Get SocketThread form param[1]
        
    CThreadedSocketItemSocketThread = (CThreadedSocketItem *)params[1];
        
    g_ThreadedSocketManager->RemoveItemFromList(SocketThread);
        
        
    // We have Removed SocketThread from list, now let the Thread destroy it self
        
    SocketThread->ThreadState(STATE_DESTROY);
        
    cell *piThreadHandle MF_GetAmxAddr(amxparams[1]);
        *
    piThreadHandle = (cell)0;
        return 
    0;

  • Convert FTP.inc, HTTP.inc to implement ThreadedSockets.
  • Fix release build of release-project on linux, Error at destroying Threads. Because of this i am distributing debug build of release project for now.
  • Test the plugins with Single Handler function for all ThreadedSocket Operations.
  • Put up a Merge request, for this module, into amxmodx.
Credits:
  • Bugsy and hackziner for their work in implementing listen and accept.
  • Arkshine and claudiuhks for this.
Changelog:
Code:
v1.0 - Initial Release
v1.1 - Added support for Dynamically changing buffer size in socket_recv_t() native.
Git Repo: https://github.com/ShootingKing-AM/ThreadedSockets

Downloads:
I am going to provide two Projects for this Module. One is debug project, which will contain some crappy printf's and some other extra comments, and Release project, which is clean and contains proper documentation.

And coming to binaries, Windows binary is release build of Release project and linux binary is debug build of Release project.
Attached Files
File Type: sma Get Plugin or Get Source (TSocksListenAccept.sma - 271 views - 2.4 KB)
File Type: sma Get Plugin or Get Source (TSocksTCP.sma - 154 views - 2.7 KB)
File Type: inc sockets.inc (12.2 KB, 129 views)
File Type: zip Projects.zip (127.8 KB, 110 views)
File Type: dll sockets_amxx.dll (67.5 KB, 237 views)
File Type: so sockets_amxx_i386.so (169.2 KB, 209 views)
File Type: zip debug-binaries.zip (225.6 KB, 83 views)
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate

Last edited by Shooting King; 05-30-2016 at 16:52. Reason: typos :mrgreen:
Shooting King is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 05-15-2015 , 14:31   Re: Module: Threaded Sockets
Reply With Quote #2

Reserved.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate
Shooting King is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-15-2015 , 17:17   Re: Module: Threaded Sockets
Reply With Quote #3

Any chance you contribute to AMXX repo on Github at some point?
__________________
Arkshine is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 05-16-2015 , 03:40   Re: Module: Threaded Sockets
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
Any chance you contribute to AMXX repo on Github at some point?
Yes, will do it after sufficient people played with this module :p Its on my todo list.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate

Last edited by Shooting King; 05-16-2015 at 11:38.
Shooting King is offline
tousif
AlliedModders Donor
Join Date: Nov 2014
Location: India
Old 05-16-2015 , 07:07   Re: Module: Threaded Sockets
Reply With Quote #5

Finally , U released it , Good
tousif is offline
insanedude
Junior Member
Join Date: Mar 2009
Old 05-16-2015 , 10:35   Re: Module: Threaded Sockets
Reply With Quote #6

And now my question comes
Could something be made about this: https://forums.alliedmods.net/showthread.php?t=255387 with this module?
insanedude is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 05-16-2015 , 11:23   Re: Module: Threaded Sockets
Reply With Quote #7

I didn't try such 'two-servers-connecting-at-a-time' thingy till now. And there shouldn't be such a problem. If there is a test code to reproduce such a crash, i will work it out.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate
Shooting King is offline
insanedude
Junior Member
Join Date: Mar 2009
Old 05-17-2015 , 17:52   Re: Module: Threaded Sockets
Reply With Quote #8

Quote:
Originally Posted by Shooting King View Post
I didn't try such 'two-servers-connecting-at-a-time' thingy till now. And there shouldn't be such a problem. If there is a test code to reproduce such a crash, i will work it out.
Well. X-redirect is the plugin.
Attached Files
File Type: sma Get Plugin or Get Source (xredirect.sma - 732 views - 110.0 KB)
File Type: sma Get Plugin or Get Source (xredirect-beta.sma - 707 views - 154.3 KB)
File Type: inc xredirect.inc (321 Bytes, 205 views)
insanedude is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 05-18-2015 , 03:18   Re: Module: Threaded Sockets
Reply With Quote #9

I am asking a plugin just to reproduce the problem. I cant figure out whats wrong in XRedirect, is it the code or the sockets, its huge and there are many things apart from just sockets Just give me small code using sockets which can reproduce the crash.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate

Last edited by Shooting King; 05-18-2015 at 03:19.
Shooting King is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 05-30-2015 , 04:16   Re: Module: Threaded Sockets
Reply With Quote #10

Last I checked. X-Redirect became obsolete and is no longer officially supported. You might wanna look into a different plugin for your experiments.
__________________
Spirit_12 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:37.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode