> Chart (Fl_Widget* , void*)
> {
> //I declared my buffer as global variables.
> 
> unsigned char dest_mac[6] = {0x32, 0x31, 0xA5, 0x5A, 0x31, 0x32};
> 
> unsigned char src_mac[6] = {0x32, 0x75, 0xA5, 0x5A, 0x31, 0x81};
> s= socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
> length = recvfrom(s, buffer, ETH_FRAME_LEN, 0, NULL, NULL);
> 
> 
> Fl::repeat_timeout(0.5, callback1);
> //every 0.5s , the function Chart will be recall. Looping the 
> function every 0.5s.
> //Each time it loop, it will fetch new data if there is data 
> sent via the server.
> }


Calling recvfrom will probably block (unless you have contrived to set
up your socket non-blocking so that you can poll on it...) and so your
whole thread will block at that point.

If your code is only a single thread, then your whole program stops
until the socket returns...

So, you have a few options:

1) If you are dead-set on polling on the socket like that, you will need
to put the socket code in a secondary thread so that your main thread
does not get blocked.

2) Use the select() call to check if there is anything on your socket
and only try to read from it when there is.

3) Use the fltk Fl::add_fd() mechanism to attach a callback to your
socket, so that the callback will run when there is data ready on your
socket (::add_fd() uses select() and/or poll() internally to achieve
this.)

My recommendation would be option 3.
-- 
Ian


SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to