Raised This Month: $79 Target: $400
 19% 

Module: Threaded Sockets


Post New Thread Reply   
 
Thread Tools Display Modes
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-01-2015 , 08:24   Re: Module: Threaded Sockets
Reply With Quote #11

I was checking your code and I have some doubts.

I didn't spent too much time but I can't find where ThreadMain is called from main module.
If I understand correctly, you tried to do the same as on mysql module and other modules you can found. In that case you manage a list of sockets to be polled at each frame or whatever timeframe you want. I can't find that.

Another question is if you have tried your calls to listent/recv/etc on udp sockets. They work slightly different and could broke how you check for incoming data.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 06-01-2015 , 11:12   Re: Module: Threaded Sockets
Reply With Quote #12

Quote:
Originally Posted by joropito View Post
I didn't spent too much time but I can't find where ThreadMain is called from main module.
If I understand correctly, you tried to do the same as on mysql module and other modules you can found. In that case you manage a list of sockets to be polled at each frame or whatever timeframe you want. I can't find that.
When a plugin calls socket_create_t() native, a Thread is created and its Entry function, TheadMain, is attached to that thread. At this moment thread state is set to STATE_IDLE (through the constructor of CThreadedSocket). So in this state, as you can see see from the main post, the Thread does nothing except checking for change in ThreadState.

I don't know exactly how Sqlite threads work, but when i looked at them, they implemented SourceMod Threads, which are not that useful(too complex) in case of Sockets. As you can see, there are no Mutex's no Semaphores etc, etc in this module. I think my Model of implementation is itself synchronous.

Quote:
Originally Posted by joropito View Post
Another question is if you have tried your calls to listent/recv/etc on udp sockets. They work slightly different and could broke how you check for incoming data.
Example ? Although i will be implementing SendTo and RecvFrom functions in this module as per Destro's request.

Thanks for your time reviewing this shit :d
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-01-2015 , 13:40   Re: Module: Threaded Sockets
Reply With Quote #13

So you have a standalone thread looping for socket handling?

I'm not sure if calling forwards it's safe from another thread. I haven't checked but I guess isn't safe at least at pawn vm. 99% of tests could work, but you may hit some problem.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 06-02-2015 , 04:06   Re: Module: Threaded Sockets
Reply With Quote #14

Quote:
Originally Posted by joropito View Post
So you have a standalone thread looping for socket handling?
Yes. One thread per socket.

Quote:
Originally Posted by joropito View Post
I'm not sure if calling forwards it's safe from another thread. I haven't checked but I guess isn't safe at least at pawn vm. 99% of tests could work, but you may hit some problem.
i guess there should't be such a problem. Did you experience such a thing ?
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-02-2015 , 16:31   Re: Module: Threaded Sockets
Reply With Quote #15

Check yourself

https://wiki.alliedmods.net/Pawn_tutorial

Quote:
No thread-safety
Pawn is targetted toward single-thread instances.
My recomendation is to keep things safe.

What you can do is to have an ipc buffer to communicate between main thread and each child thread so you can keep your thread working like now but forwards should be called from main thread.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 06-03-2015 , 10:33   Re: Module: Threaded Sockets
Reply With Quote #16

If we make such a buffer, when and how do we check for a change in such buffer in main thread ? Do note a point that we are talking about 1% of all cases.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-03-2015 , 11:10   Re: Module: Threaded Sockets
Reply With Quote #17

Quote:
Originally Posted by Shooting King View Post
If we make such a buffer, when and how do we check for a change in such buffer in main thread ? Do note a point that we are talking about 1% of all cases.
StartFrame() is a good start.
Check dlls/mysqlx/threading.cpp on amxmodx source code.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 06-03-2015 , 13:39   Re: Module: Threaded Sockets
Reply With Quote #18

Quote:
Originally Posted by joropito View Post
StartFrame() is a good start.
Check dlls/mysqlx/threading.cpp on amxmodx source code.
Then we will be using much resources just for checking Buffer StartFrame is called too many time per second. Any other good alternative ? I really don't want to depend on engine/game functions.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 06-03-2015 at 13:44.
Shooting King is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-03-2015 , 14:30   Re: Module: Threaded Sockets
Reply With Quote #19

You're doing modules, not plugins. On plugins it's expensive in time because stack and calls.

A lot of modules uses StartFrame, it not too expensive in this case.

You have to do in game loop so it should be done in some game call.
If you don't like to use directly StartFrame, do in 1/10 calls of it.
Also you can create a dummy entity with custom Think time where you check for available data, but you will spent 1 entity from your limited max ent number...
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Javivi
AlliedModders Donor
Join Date: Dec 2008
Old 06-09-2015 , 08:43   Re: Module: Threaded Sockets
Reply With Quote #20

Nice job. I was working on an update but this one is way better, so be sure to push it to amxmodx's github.

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.

https://github.com/Javivi/amxmodx/co...sockets-update

Biggest changes are:
Code:
- WinSock version changed from 1.1 to 2.2.
- Properly check for WinSock initialization on OnAmxxAttach/Detach.
- Now, natives will not be added if we can't start up WinSock.
- socket_open is now IP version agnostic (both IPv4 and IPv6 are
supported).
- Error reporting has been changed on socket_open, now it returns the
actual libc errors instead of the previous made-up errors.
- socket_close now returns a value on success/failure.
- Code rewritten to be more readable, it should be self-explaining now.
__________________
Javivi 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 07:40.


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