c - Handle postthreadmessage() inside a thread which is blocking in while(1) loop or use "Event Driven Sockets" -


i have single server multiple client udp application. there single thread (thread#1) single socket (socket#1) receive data client#1 continuously. task of receiving thread continuously receive data @ socket.

i have button says "send data client#1" on server application gui. when button pressed, want receiveing thread suspend reception , send data on socket#1 , when data sent, continuous reception resumed.

how can done? if postthreadmessage() when button presses, receiving thread has no check these posted messages since inside while loop receiving messages. how can check posted message corresponding buttons pressed?

edit: suggestion

what if make socket "event driven"? i.e. whenever there data available @ socket read, fd_read event generated , can read on socket, , whenever want write data on socket, generate event fd_wanttowrite , data written on socket. similar possible?

(i know fd_read not sure fd_wanttowrite when wish write on socket)

you don't need pause reading thread. send/to() data inside button click handler using same socket (or different socket, since udp connectionless).

the real reason pause reading thread if sent data receives response not want receiving thread see. if case, have few choices:

  1. have receiving thread pass responses button click handler processing when needed.

  2. add flag receiving thread tells stop reading socket. have button set flag while sending, clear flag when finished. have receiving thread's loop use select() small timeout each iteration of loop can check flag , skip reading if flag set.

  3. switch event-driven socket , use message loop in receiving thread, suggested. can pass messages thread, such message tell skip reading when fd_read messages arrive, , message resume reading. if want thread call send/to() on button's behalf, can have message that, , reading implicitly blocked while sending in progress.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -