LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-23-2012, 01:21 AM   #1
yaplej
Member
 
Registered: Apr 2009
Distribution: CentOS, Ubuntu, openSuSE
Posts: 148
Blog Entries: 1

Rep: Reputation: 22
CLI using message queue


Hello,

I have been trying to implement a full-duplex cli to a daemon I am working on. So far I have been able to either send or receive from my IPC thread but not both. I think that by using something like select() or poll() I should be able to implement both sending and receiving from the message queue in a single thread.

Am I going about this all wrong and should just go the two thread route? It seems like that would be very clunky to require four threads just to handle sending and receiving messages between the daemon and cli application.

Anyone is more than welcome to visit my project and give me hints/tips at improving it. This is the CLI IPC/API I am trying to write.
http://opennop.svn.sourceforge.net/v...68&view=markup

Your guidance would be much appreciated.
 
Old 03-24-2012, 01:51 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
It probably depends on when the daemon will need to send information. Does the daemon need to write to the message queue even when no cli process is reading the messages? Are the messages sent by the daemon in response to the incoming messages? I use local sockets for this type of thing, but I only use synchronous IPC for cli/daemon communication.
Kevin Barry
 
Old 03-26-2012, 01:04 AM   #3
yaplej
Member
 
Registered: Apr 2009
Distribution: CentOS, Ubuntu, openSuSE
Posts: 148
Blog Entries: 1

Original Poster
Rep: Reputation: 22
Yes, the daemon will have to send messages back to the cli. The majority of the output will be in response to a message from the cli but some output will be sent to the cli without request. In the case of debug messages being turned on for specific routines it will generate messages and send them to the cli.
 
Old 03-26-2012, 01:27 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
So, is it safe to say that the same thing could be done with a socket? Have you considered using a local socket to initiate the connection?
Kevin Barry
 
Old 04-02-2012, 06:15 PM   #5
yaplej
Member
 
Registered: Apr 2009
Distribution: CentOS, Ubuntu, openSuSE
Posts: 148
Blog Entries: 1

Original Poster
Rep: Reputation: 22
Yes, it probably could be done using a local socket. Would my initial problem still remain? If I need a full-duplex/async communications channel wouldnt I still need somehow to break out of the "read socket" in order to send a message?
 
Old 04-03-2012, 12:45 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
After you accept a connection, you would set the socket to non-blocking (which can be made default if you you apply it to the listening socket) and use select with a timeout. If you're blocked for a read on a socket then an attempted write should block; therefore, you'd need to either prevent blocking or dup2 the socket so you have a second copy for writing. Alternatively, you could just read from the socket when you have time between other operations; if there isn't any data available then it will fail immediately. If you need buffered input (i.e. a FILE*) then you'd want to avoid select, and instead fdopen then use fgets, etc. to test for and read input at the same time. Lastly, you could set the O_ASYNC flag on the socket and receive a signal when data is made available. In all cases, you'll either need to block somewhere in your code or use some sort of "sleep" to control the processor usage.
Kevin Barry
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CUPS web interface: IPP printer queue cannot be started (CLI works fine) lefty.crupps Linux - Software 0 04-07-2010 11:37 AM
Is it possible for me to write in front of queue in case of message queue? hemanthv414 Linux - Newbie 1 11-17-2008 04:40 PM
Message Queue sarcastodon Programming 0 12-26-2006 10:09 AM
programming for message queue and such ... feetyouwell Programming 0 10-18-2004 04:54 PM
Qmail Message Queue dadepfan Linux - Software 0 07-22-2004 03:54 PM


All times are GMT -5. The time now is 09:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration