Raised This Month: $ Target: $400
 0% 

Module: Threaded Sockets


Post New Thread Reply   
 
Thread Tools Display Modes
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 06-11-2015 , 04:28   Re: Module: Threaded Sockets
Reply With Quote #21

Quote:
Originally Posted by Javivi View Post
Nice job. I was working on an update but this one is way better, so be sure to push it to amxmodx's github.
Sure, Thanks.

Quote:
Originally Posted by Javivi View Post
Feel free to take any code you want to improve your module, as I've seen that you didn't change much of the default code.
Yes, I didn't change any of the normal natives code, because i don't think there are any complaints regarding default sockets.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 06-11-2015 , 13:44   Re: Module: Threaded Sockets
Reply With Quote #22

socket_recv_t()

It does not support a binary transfer (null byte)?

@EDIT
suggestions:
- Add the "iThreadHandle" param on callbacks or a array to pass custom data (if you do this, you could remove "iThreadState" and not implement "iThreadHandle")
- Remove param "protocol", only support TCP.
- iRecvDataLen is bytes received
- Check callback valid public fuction
- Support null bytes for recv

@EDIT2
win2008:
50% CPU usage on STATE_READ

code:
Spoiler


@EDIT3
I haven't thought before, but threads are totally unnecessary, you can use non-blocking mode.

@EDIT4
Really I needed something functional now xd.

Github:
Github / Destro- / amxx / sockets_async

Last version


Spoiler
__________________

Last edited by Destro-; 06-22-2015 at 14:28.
Destro- is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 08-18-2015 , 16:41   Re: Module: Threaded Sockets
Reply With Quote #23

Destro-, nice job!

But please, add from native module this one:
Code:
/* Same as socket_send but Data can contain null bytes */

native socket_send2(_socket, const _data[], _length);
Or just update current socket_send to able sending null bytes. Thanks in advance if you could do it quickly!)
__________________

Last edited by draft; 08-18-2015 at 16:44.
draft is offline
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 08-19-2015 , 18:16   Re: Module: Threaded Sockets
Reply With Quote #24

socket_send support null bytes
__________________
Destro- is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 08-20-2015 , 13:40   Re: Module: Threaded Sockets
Reply With Quote #25

PHP Code:
#include <amxmodx>
#include <sockets_async>

#define PLUGIN "Test ASync Null Bytes"
#define VERSION "1.0"
#define AUTHOR "AImpressor"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_srvcmd("test_send""test_send")
}

public 
test_send() {
    new 
SOCKET:socket socket_create(SOCK_TYPE_TCP0)
    
socket_connect(socket"127.0.0.1"80)
}

public 
fw_sockConnected(SOCKET:socketcustomID)
{
    new 
packet[256]
    
formatex(packet255"%c%c%c%c"0x000x000x000x00)
    new 
len socket_send(socketpacket)
    
log_amx("Sending packet len: %d"len)

When im using "test_send", it gives me answer "Sending packet len: 0" - that means it ignores all my null bytes. Tested it on windows server with web. Could you please resolve this issue?
__________________
draft is offline
Old 08-20-2015, 19:29
Destro-
This message has been deleted by Destro-. Reason: no reference to the thread
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 08-21-2015 , 13:00   Re: Module: Threaded Sockets
Reply With Quote #26

Thx, this worked for me! But the disadvantage is that we should always count exact number of bytes in code to send them. And if i need, for example, 3 null bytes at the end, it is required to make len + 3 to send them correctly.

Please, update sockets_async.inc to this code. It allows the module to autoload instead of writing it in modules.ini.
PHP Code:
#if AMXX_VERSION_NUM >= 175
    #pragma reqlib sockets_async
    #if !defined AMXMODX_NOAUTOLOAD
        #pragma loadlib sockets_async
    #endif
#else
    #pragma library sockets_async
#endif 
Also, ive found that if 2 or more plugins are using this module there are several memory collisions between them. It means that if im sending info in second plugin, then im recving it in first of them that has fw_sockReadable hook. May be, im doing smth wrong, but in native amxx modules there are not collisions between plugins.
__________________
draft is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 09-10-2015 , 07:17   Re: Module: Threaded Sockets
Reply With Quote #27

Hi, in last version of this module in LINUX there is always error 115 (SOCK_INPROGRESS) at crear connection (when im using socket_connect function in plugin. Ive tried to overpass that error by modifying the source of module but now after socket_create nothing happenes, seems, that socket is always non-writable while in windows server this works fine.
Could you please fix this issue?
__________________

Last edited by draft; 09-10-2015 at 07:18.
draft is offline
Old 09-10-2015, 13:10
Destro-
This message has been deleted by Destro-.
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 09-11-2015 , 13:01   Re: Module: Threaded Sockets
Reply With Quote #28

Let me make myself clear again,
Quote:
This module eliminates looping, hidden looping, entity thinks in plugin as well as in the main thread.
Destro, you are just continuously looping and checking if there is any change in state of the socket, you don't know the exact time when your asyn sockets respond to your command(connect, send,...) similar to the includes aforementioned and hence looping becomes inevitable. But in game engines, we cannot afford that many number of false checking in loops on the same thread on which main HLDS functions are running (that too on StartFrame()). So what my module actually does is, it separates these loops from the main thread and keeps them on a Child Thread, eliminating false checks on the main thread. These child threads will inform the main thread when there is a change in state of the socket and executes a corresponding forward.

Your module is a module level implementation of what Bugsy's includes and others does and is more efficient (ofcourse). You are free to start a new thread in Module Section for your Async-Sockets, but its different from mine (atleast in theory).
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 09-15-2015 , 09:09   Re: Module: Threaded Sockets
Reply With Quote #29

Shooting King,
Could you please make your API more useful?
I mean that for example we are sending multiply socket queries in one time, how can i understand in callback which one is answering of them? There is no way in plugin to add custom information in callback (for example, playerID for which im sending socket query) and in ur examples u are using single global variable for that purpose which is highly unappreciated.
In AMX there is set_task function that allows us to send custom information in callback, could you upgrade your module and API to something similar? Or may be u can use Destro API, it is also not bad.

BTW:
Quote:
suggestions:
- Add the "iThreadHandle" param on callbacks or a array to pass custom data (if you do this, you could remove "iThreadState" and not implement "iThreadHandle")
__________________

Last edited by draft; 09-15-2015 at 09:10.
draft is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 09-16-2015 , 11:35   Re: Module: Threaded Sockets
Reply With Quote #30

I am not sure i understood you draft, Can you give me an Example ? And tell me what you want to do ? Actually i didn't understand that suggestion too
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King 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 10:26.


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