!SGkzNqBXEJutSYnahE:matrix.org

C Programming Language

277 Members
C Programming Ask C related questions here.28 Servers

Load older messages


SenderMessageTime
22 Oct 2021
@thoth:cuum.spacethothAnd poll is so much simpler and cleaner uwu and select's man page even recommends to use it. One hassle less.15:02:18
@thoth:cuum.spacethothSometimes more complex != more performance :)15:02:54
@thoth:cuum.spacethoth Thanks tthom, we can chat again maybe after I read the article you linked?
You were such a help and a encouragement and made me feel so good uwu
15:13:09
@tthom:ahtoms.xyztthomNo probs15:49:32
@thoth:cuum.spacethoth
In reply to @tthom:ahtoms.xyz
Data is sent to those file descriptors, events like POLLIN are watched by poll to see if data had been written to that file which the file descriptor maps to. When it stops waiting, it isn't that it knows what exact file descriptor got the data but it knows at least one in the set of file descriptors it is watching received a signal
Hmm where would I have the POLL things then? Because by how we talked - I planned on having POLL on each thread, but if every thread check if the file descriptor of the next POLL's incoming data is the one the current thread is working for, then that'll be like x30 of something energy waste..
16:33:31
@thoth:cuum.spacethothI might have poll and accept in the main aka producer thread.16:33:46
@thoth:cuum.spacethothOpinions, worries, questions?16:33:58
@tthom:ahtoms.xyztthomYou could simply just attempt to do poll on a single thread and compare your results with your multi-threaded application, if you are going to use poll with multiple threads, you could have a set number of connections a single thread manages.16:35:00
@thoth:cuum.spacethothI do - 1 xD16:38:00
@thoth:cuum.spacethothOr did you mean yet another thread, for poll-managing?16:38:27
@thoth:cuum.spacethothThat might be ideal.. Have 1 main thread aka producer - accept connections Have say 1 thread aka police-men - forward poll-incoming and outgoing traffic to other threads Other threads - handle the incoming/outgoing traffic16:40:02
@thoth:cuum.spacethoth * That might be ideal.. Have 1 main thread aka producer - accept connections Have say 1 thread aka police-men - forward poll-incoming and outgoing traffic to other threads Other threads - handle the incoming/outgoing traffic16:40:04
@thoth:cuum.spacethoth
In reply to @thoth:cuum.space
Or did you mean yet another thread, for poll-managing?
As to not slow down any incoming clients
16:43:25
@tthom:ahtoms.xyztthomJust one thread (main) is required with poll, just set up an array with the number of file descriptors you want to handle and have a loop where it will detect the event, find the file descriptor it occurred on and you have a function that operates on it. Do note, you would likely want to set handling of these files to non-blocking as well17:11:39
@thoth:cuum.spacethothYeah, it shouldn't be that slow xD17:20:50
@thoth:cuum.spacethoth
In reply to @thoth:cuum.space
That might be ideal..
Have 1 main thread aka producer - accept connections
Have say 1 thread aka police-men - forward poll-incoming and outgoing traffic to other threads
Other threads - handle the incoming/outgoing traffic
This would only add complexity
17:21:04
@thoth:cuum.spacethoth
In reply to @tthom:ahtoms.xyz
Just one thread (main) is required with poll, just set up an array with the number of file descriptors you want to handle and have a loop where it will detect the event, find the file descriptor it occurred on and you have a function that operates on it.

Do note, you would likely want to set handling of these files to non-blocking as well
You mean the timeout parameter in poll?
17:21:53
@tthom:ahtoms.xyztthomFrom memory you can set it to -1 and it holds until a signal is generated17:23:17
@tthom:ahtoms.xyztthomIf you want it to do work when there is no activity, then give it a timeout that you think is reasonable17:25:00
@thoth:cuum.spacethoth
In reply to @tthom:ahtoms.xyz
From memory you can set it to -1 and it holds until a signal is generated

I know, that's the blocking, and yuo said to set it to non-blocking lol

What you probably meant is set it to 1?

17:26:05
@thoth:cuum.spacethothBecause I might want to do stuff even if there's nothing to receive?17:26:23
@tthom:ahtoms.xyztthomnon-blocking is meant to be described to the file descriptor17:26:24
@thoth:cuum.spacethothor I might just be dumb IDK I'll figure it out17:26:30
@tthom:ahtoms.xyztthomBy default, all reads are blocking17:26:34
@thoth:cuum.spacethoth
In reply to @tthom:ahtoms.xyz
If you want it to do work when there is no activity, then give it a timeout that you think is reasonable
That's what I meant sorry
17:26:54
@thoth:cuum.spacethothDidn't read on time17:26:57
@thoth:cuum.spacethoth
In reply to @tthom:ahtoms.xyz
By default, all reads are blocking
I know man, I read some shit :D *proud badge show-off *
17:27:17
@tthom:ahtoms.xyztthomSo say like you go read(fd, buf, 256); It will wait until there is data there. You want to call fcntl with O_NONBLOCK flag (probably want to do this twice so you get the bits and the second time to get the bits with new bit set to say it should be non-blocking).17:28:49
@thoth:cuum.spacethothI am confused with the last part18:32:50
@thoth:cuum.spacethothBut I did see fcntl and O_NONBLOCK things in some code and in man pages18:33:10

There are no newer messages yet.


Back to Room List