So far I have been using the linux api and boost libraries in this project so ideally I’d like to stick to those.
I am trying to find out how many bytes my server is sending in a second. My plan is to just have a variable which will reset every second that I append the return value of the send() function to every time I send(the return value is the # of bytes sent).
The problem is: how will I know when to stop appending to the variable? I would like some type of interrupt event which would tell me “Hey, it has been a second! Record the bytes sent and reset the variable before appending to it again!” I already have an epoll setup so if I could add some type of file descriptor that I would poll with epoll that would be ideal!
Any and all advice/suggestions are appreciated. Thank you in advance!
P.S: An idea I have is to have a timer thread. It sleeps for a second then when it wakes up it writes to a message queue. Since message queue’s can be polled by epoll I would get the event and know. The sleeper thread would just continue looping. Any better ideas?
Set up a
SIGALRMhandler to terminate the measurement, then callalarm(2)with the time you want to measure for in seconds.