All,
I am looking for a C++ wrapper over BSD socket library. I plan to use
socket i/o during telecom call processing in a thread so that thread
is not blocked when it is making read/write call. It can move to next
message processing after saving the current call context. It can
resume the processing of this call when it receive the i/o complete
notification.
thanks
Ittium
|
|
0
|
|
|
|
Reply
|
ittium (65)
|
2/19/2011 7:26:42 AM |
|
On Fri, 18 Feb 2011, junk junk wrote:
>All,
>I am looking for a C++ wrapper over BSD socket library. I plan to use
>socket i/o during telecom call processing in a thread so that thread
>is not blocked when it is making read/write call. It can move to next
>message processing after saving the current call context. It can
>resume the processing of this call when it receive the i/o complete
>notification.
>thanks
>Ittium
>
Why do you want a C++ wrapper? You can call the socket library directly, use the
SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
inform you about available data (You'll get the SIGIO signal then).
|
|
0
|
|
|
|
Reply
|
Tobias
|
2/19/2011 10:12:02 AM
|
|
junk junk wrote:
> All,
> I am looking for a C++ wrapper over BSD socket library. I plan to use
> socket i/o during telecom call processing in a thread so that thread
> is not blocked when it is making read/write call. It can move to next
> message processing after saving the current call context. It can
> resume the processing of this call when it receive the i/o complete
> notification.
> thanks
> Ittium
See the boost asio library from boost.org. Docs are at:
http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio.html
Jeff
|
|
0
|
|
|
|
Reply
|
Jeff
|
2/19/2011 6:38:55 PM
|
|
On Feb 19, 3:12=A0pm, Tobias Blass <tobiasbl...@gmx.net> wrote:
> On Fri, 18 Feb 2011, junk junk wrote:
> >All,
> >I am looking for a C++ wrapper over BSD socket library. I plan to use
> >socket i/o during telecom call processing in a thread so that thread
> >is not blocked when it is making read/write call. It can move to next
> >message processing after saving the current call context. It can
> >resume the processing of this call when it receive the i/o complete
> >notification.
> >thanks
> >Ittium
>
> Why do you want a C++ wrapper? You can call the socket library directly, =
use the
> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) t=
o wait
> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the k=
ernel
> inform you about available data (You'll get the SIGIO signal then).
You are right, I can call the BSD APIs directly. I need C++ wrapper
since rest of the code is in C++.
I am not sure how good will be performance with SIGIO, when a thread
is working upon multiple socket
fd. Let us no forget, the thread safety issues with signal. SELECT and
POLL are definitely promising.
|
|
0
|
|
|
|
Reply
|
junk
|
2/20/2011 5:46:22 AM
|
|
On 02/20/11 06:46 PM, junk junk wrote:
> On Feb 19, 3:12 pm, Tobias Blass<tobiasbl...@gmx.net> wrote:
>> On Fri, 18 Feb 2011, junk junk wrote:
>>> All,
>>> I am looking for a C++ wrapper over BSD socket library. I plan to use
>>> socket i/o during telecom call processing in a thread so that thread
>>> is not blocked when it is making read/write call. It can move to next
>>> message processing after saving the current call context. It can
>>> resume the processing of this call when it receive the i/o complete
>>> notification.
>>> thanks
>>> Ittium
>>
>> Why do you want a C++ wrapper? You can call the socket library directly, use the
>> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
>> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
>> inform you about available data (You'll get the SIGIO signal then).
>
> You are right, I can call the BSD APIs directly. I need C++ wrapper
> since rest of the code is in C++.
So? Most of my code is C++, but I still use the socket API.
> I am not sure how good will be performance with SIGIO, when a thread
> is working upon multiple socket
> fd. Let us no forget, the thread safety issues with signal. SELECT and
> POLL are definitely promising.
Whether you use multiple threads and blocking or non-blocking with poll
really depends on you workload and whether you can use multiple cores to
process your data. On a single core, poll is much easier to use.
--
Ian Collins
|
|
0
|
|
|
|
Reply
|
Ian
|
2/20/2011 5:55:47 AM
|
|
Tobias Blass <tobiasblass@gmx.net> wrote:
<snip>
> Why do you want a C++ wrapper? You can call the socket library directly, use the
> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
> inform you about available data (You'll get the SIGIO signal then).
SOCK_NONBLOCK is a Linux extension.
O_ASYNC is tricky to handle because of overflow and other signal handling
issues. Nobody should be using O_ASYNC these days.
|
|
0
|
|
|
|
Reply
|
William
|
2/20/2011 6:28:30 AM
|
|
On Feb 20, 11:28=A0am, William Ahern <will...@wilbur.25thandClement.com>
wrote:
> Tobias Blass <tobiasbl...@gmx.net> wrote:
>
> <snip>
>
> > Why do you want a C++ wrapper? You can call the socket library directly=
, use the
> > SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2)=
to wait
> > on the data. You can also set the O_ASYNC flag via fcntl(2) and let the=
kernel
> > inform you about available data (You'll get the SIGIO signal then).
>
> SOCK_NONBLOCK is a Linux extension.
>
> O_ASYNC is tricky to handle because of overflow and other signal handling
> issues. Nobody should be using O_ASYNC these days.
Problem I am trying to solve is simple
1. Multiple threads want to send the data on a shared socket fd but
they can not perform blocking call since they are highly loaded and
has other tasks to do.
2. Thread want to read from its **exclusive** socket, but it should
not be blocked since it is loaded and has other tasks to do.
I am currently evaluating boost asio
thanks
Ittium
|
|
0
|
|
|
|
Reply
|
junk
|
2/20/2011 7:01:48 AM
|
|
On Sat, 19 Feb 2011, William Ahern wrote:
>Tobias Blass <tobiasblass@gmx.net> wrote:
><snip>
>> Why do you want a C++ wrapper? You can call the socket library directly, use the
>> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
>> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
>> inform you about available data (You'll get the SIGIO signal then).
>
>SOCK_NONBLOCK is a Linux extension.
>
>O_ASYNC is tricky to handle because of overflow and other signal handling
>issues. Nobody should be using O_ASYNC these days.
>
Ok thank you for the clarification. I just had something in mind that you
could use SIGIO (haven't ever used it myself) so I just looked over the
manpage. If SOCK_NONBLOCK is a linux extension how can you tell the socket
not to block on read(2) on other Unix flavors?
|
|
0
|
|
|
|
Reply
|
Tobias
|
2/20/2011 9:42:54 AM
|
|
On 02/20/11 10:42 PM, Tobias Blass wrote:
> On Sat, 19 Feb 2011, William Ahern wrote:
>
>> Tobias Blass<tobiasblass@gmx.net> wrote:
>> <snip>
>>> Why do you want a C++ wrapper? You can call the socket library directly, use the
>>> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
>>> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
>>> inform you about available data (You'll get the SIGIO signal then).
>>
>> SOCK_NONBLOCK is a Linux extension.
>>
>> O_ASYNC is tricky to handle because of overflow and other signal handling
>> issues. Nobody should be using O_ASYNC these days.
>>
> Ok thank you for the clarification. I just had something in mind that you
> could use SIGIO (haven't ever used it myself) so I just looked over the
> manpage. If SOCK_NONBLOCK is a linux extension how can you tell the socket
> not to block on read(2) on other Unix flavors?
By using fcntl to set the O_NONBLOCK flag on the file descriptor.
--
Ian Collins
|
|
0
|
|
|
|
Reply
|
Ian
|
2/20/2011 9:55:39 AM
|
|
William Ahern <william@wilbur.25thandClement.com> writes:
> Tobias Blass <tobiasblass@gmx.net> wrote:
> <snip>
>> Why do you want a C++ wrapper? You can call the socket library directly, use the
>> SOCK_NONBLOCK flag when you call socket(2) and use poll(2) or select(2) to wait
>> on the data. You can also set the O_ASYNC flag via fcntl(2) and let the kernel
>> inform you about available data (You'll get the SIGIO signal then).
>
> SOCK_NONBLOCK is a Linux extension.
>
> O_ASYNC is tricky to handle because of overflow and other signal handling
> issues. Nobody should be using O_ASYNC these days.
I disagree with that. O_ASYNC, especially when combined with the
'Linux extensions' for that (meaning, it works for all file
descriptors) is a really useful interface and often, even the one
which is easiest to use one[*].
[*] One of the programs I presently work on is written in
Perl. Perl doesn't really offer anything sensible wrt I/O
multiplexing on its own (I refuse to use select for anything
and Graham Barr's poll module is implemented in a completely
braindead way [basically, it make poll inherit the inherent
deficiencies of select by constructing a new, dynamically allocated
pollfd array for each call]) and making sigwaitinfo available
in Perl required far less code than providing a sensible
poll-interface. Also, this meant being able to use a uniform
event notification mechanism (signals) for all events I'm
interested in (I/O readiness notification, SIGALRM, manually
sent signals, 'child process death' events instead of 'using a
file-descriptor based approach and shoe-horning signal
processing into that. 'Signal queue overflow' is easily dealt
with by simply marking all descriptors as 'I/O ready' and let
the ordinary I/O event handlers sort the actual descriptor
states out (they need to be able to deal with this, anyway).
|
|
0
|
|
|
|
Reply
|
Rainer
|
2/20/2011 8:35:06 PM
|
|
Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> William Ahern <william@wilbur.25thandClement.com> writes:
<snip>
> > O_ASYNC is tricky to handle because of overflow and other signal handling
> > issues. Nobody should be using O_ASYNC these days.
> I disagree with that. O_ASYNC, especially when combined with the
> 'Linux extensions' for that (meaning, it works for all file
> descriptors) is a really useful interface and often, even the one
> which is easiest to use one[*].
> [*] One of the programs I presently work on is written in
> Perl. Perl doesn't really offer anything sensible wrt I/O
> multiplexing on its own (I refuse to use select for anything
> and Graham Barr's poll module is implemented in a completely
> braindead way [basically, it make poll inherit the inherent
> deficiencies of select by constructing a new, dynamically allocated
> pollfd array for each call]) and making sigwaitinfo available
> in Perl required far less code than providing a sensible
> poll-interface. Also, this meant being able to use a uniform
> event notification mechanism (signals) for all events I'm
> interested in (I/O readiness notification, SIGALRM, manually
> sent signals, 'child process death' events instead of 'using a
> file-descriptor based approach and shoe-horning signal
> processing into that. 'Signal queue overflow' is easily dealt
> with by simply marking all descriptors as 'I/O ready' and let
> the ordinary I/O event handlers sort the actual descriptor
> states out (they need to be able to deal with this, anyway).
>
Fair enough. The way I figured it, O_ASYNC is on the one hand non-portable,
yet where it is supported there is kqueue or epoll/signalfd, neither of
which require overflow handling or careful signal masking. So I figured, why
use O_ASYNC? But I guess the answer is convenience.
Linux looks like it can deliver the descriptor number with SIGPOLL. Does it
dequeue the signal when the descriptor is closed?
|
|
0
|
|
|
|
Reply
|
William
|
2/20/2011 11:00:53 PM
|
|
William Ahern <william@wilbur.25thandClement.com> writes:
> Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>> William Ahern <william@wilbur.25thandClement.com> writes:
> <snip>
>> > O_ASYNC is tricky to handle because of overflow and other signal handling
>> > issues. Nobody should be using O_ASYNC these days.
[...]
>> [*] One of the programs I presently work on is written in
>> Perl. Perl doesn't really offer anything sensible wrt I/O
>> multiplexing on its own (I refuse to use select for anything
>> and Graham Barr's poll module is implemented in a completely
>> braindead way [basically, it make poll inherit the inherent
>> deficiencies of select by constructing a new, dynamically allocated
>> pollfd array for each call]) and making sigwaitinfo available
>> in Perl required far less code than providing a sensible
>> poll-interface. Also, this meant being able to use a uniform
>> event notification mechanism (signals) for all events I'm
>> interested in (I/O readiness notification, SIGALRM, manually
>> sent signals, 'child process death' events instead of 'using a
>> file-descriptor based approach and shoe-horning signal
>> processing into that. 'Signal queue overflow' is easily dealt
>> with by simply marking all descriptors as 'I/O ready' and let
>> the ordinary I/O event handlers sort the actual descriptor
>> states out (they need to be able to deal with this, anyway).
>>
>
> Fair enough. The way I figured it, O_ASYNC is on the one hand non-portable,
> yet where it is supported there is kqueue or epoll/signalfd, neither of
> which require overflow handling or careful signal masking. So I figured, why
> use O_ASYNC? But I guess the answer is convenience.
I'm actually using epoll/signalfd at the same time in C code but I
have used O_ASYNC in the past whenever it seemed more convenient. But
for Perl, implementing an XS interface to sigtimedwait/ sigwaitinfo
and to the siginfo structure needed just 124 lines of C and a
reasonably usable epoll/ signalfd interface had certainly needed much
more than this (I wrote a 'sensible' poll interface for Perl in the
past [got sold to someone, so I'm not allowed to use it anymore :-(]
and that was already about twice this amount of code.
> Linux looks like it can deliver the descriptor number with SIGPOLL. Does it
> dequeue the signal when the descriptor is closed?
AFAIK not.
|
|
0
|
|
|
|
Reply
|
Rainer
|
2/22/2011 3:34:34 PM
|
|
On Feb 22, 8:34=A0pm, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> William Ahern <will...@wilbur.25thandClement.com> writes:
> > Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> >> William Ahern <will...@wilbur.25thandClement.com> writes:
> > <snip>
> >> > O_ASYNC is tricky to handle because of overflow and other signal han=
dling
> >> > issues. Nobody should be using O_ASYNC these days.
>
> [...]
>
>
>
>
>
>
>
>
>
> >> =A0 =A0 =A0 =A0 [*] One of the programs I presently work on is written=
in
> >> =A0 =A0 =A0 =A0 Perl. Perl doesn't really offer anything sensible wrt =
I/O
> >> =A0 =A0 =A0 =A0 multiplexing on its own (I refuse to use select for an=
ything
> >> =A0 =A0 =A0 =A0 and Graham Barr's poll module is implemented in a comp=
letely
> >> =A0 =A0 =A0 =A0 braindead way [basically, it make poll inherit the inh=
erent
> >> =A0 =A0 =A0 =A0 deficiencies of select by constructing a new, dynamica=
lly allocated
> >> =A0 =A0 =A0 =A0 pollfd array for each call]) and making sigwaitinfo av=
ailable
> >> =A0 =A0 =A0 =A0 in Perl required far less code than providing a sensib=
le
> >> =A0 =A0 =A0 =A0 poll-interface. Also, this meant being able to use a u=
niform
> >> =A0 =A0 =A0 =A0 event notification mechanism (signals) for all events =
I'm
> >> =A0 =A0 =A0 =A0 interested in (I/O readiness notification, SIGALRM, ma=
nually
> >> =A0 =A0 =A0 =A0 sent signals, 'child process death' events instead of =
'using a
> >> =A0 =A0 =A0 =A0 file-descriptor based approach and shoe-horning signal
> >> =A0 =A0 =A0 =A0 processing into that. 'Signal queue overflow' is easil=
y dealt
> >> =A0 =A0 =A0 =A0 with by simply marking all descriptors as 'I/O ready' =
and let
> >> =A0 =A0 =A0 =A0 the ordinary I/O event handlers sort the actual descri=
ptor
> >> =A0 =A0 =A0 =A0 states out (they need to be able to deal with this, an=
yway).
>
> > Fair enough. The way I figured it, O_ASYNC is on the one hand non-porta=
ble,
> > yet where it is supported there is kqueue or epoll/signalfd, neither of
> > which require overflow handling or careful signal masking. So I figured=
, why
> > use O_ASYNC? But I guess the answer is convenience.
>
> I'm actually using epoll/signalfd at the same time in C code but I
> have used O_ASYNC in the past whenever it seemed more convenient. But
> for Perl, implementing an XS interface to sigtimedwait/ sigwaitinfo
> and to the siginfo structure needed just 124 lines of C and a
> reasonably usable epoll/ signalfd interface had certainly needed much
> more than this (I wrote a 'sensible' poll interface for Perl in the
> past [got sold to someone, so I'm not allowed to use it anymore :-(]
> and that was already about twice this amount of code.
>
> > Linux looks like it can deliver the descriptor number with SIGPOLL. Doe=
s it
> > dequeue the signal when the descriptor is closed?
>
> AFAIK not.
thanks group for the responses
I am curious if posix aio is used for sockets on linux. I did some
googling it seems its support is limited and not stable.
ittium
|
|
0
|
|
|
|
Reply
|
junk
|
2/23/2011 4:45:59 AM
|
|
|
12 Replies
831 Views
(page loaded in 0.216 seconds)
Similiar Articles: C++ wrapper for async socket calls. - comp.unix.programmer ...All, I am looking for a C++ wrapper over BSD socket library. I plan to use socket i/o during telecom call processing in a thread so that thread is ... Delay in C on linux or OSS - comp.lang.cDelay in C on linux or OSS - comp.lang.c C++ wrapper for async socket calls. - comp.unix.programmer ... Delay in C on linux or OSS - comp.lang.c way to comply is with that ... readline() with select() on STDIN - comp.unix.programmer ...If you have many sockets the async approach is not a very good idea; if that's ... C++ wrapper for async socket calls. - comp.unix.programmer ... readline() with select() on ... Unix Systems Programming Newbie - exec format error - comp.unix ...I'm writting a C/sockets client interface on Solaris. I've based the ... C++ wrapper for async socket calls. - comp.unix.programmer ... "Interrupted system call", read ... Sending ASCII EOT signal over TCP/IP sockets - comp.unix ...C++ wrapper for async socket calls. - comp.unix.programmer ... Sending ASCII EOT signal over TCP/IP sockets - comp.unix ... I'm creating the socket with the following call ... socket with sigio - comp.unix.programmerC++ wrapper for async socket calls. - comp.unix.programmer ... > I am not sure how good will be performance with SIGIO, when a thread > is working upon multiple socket > fd. socket in use ? - comp.protocols.time.ntpC++ wrapper for async socket calls. - comp.unix.programmer ... All, I am looking for a C++ wrapper over BSD socket library. I plan to use socket i/o during telecom call ... bind() and connect() issues [Newbie] - comp.unix.solaris ...C++ wrapper for async socket calls. - comp.unix.programmer ... bind() and connect() issues [Newbie] - comp.unix.solaris ... C++ wrapper for async socket calls. - comp.unix ... some GPIB-tcl questions - comp.lang.tclC++ wrapper for async socket calls. - comp.unix.programmer ... I did some googling it seems its support is limited and not stable. ittium ... some GPIB-tcl questions ... select() and file descriptor usage troubles - comp.unix.programmer ...C++ wrapper for async socket calls. - comp.unix.programmer ... select() and file descriptor usage troubles - comp.unix.programmer ... Hello All I am an experienced C ... arena: wait/signal and queue blocking - comp.simulationC++ wrapper for async socket calls. - comp.unix.programmer ..... processing in a thread so that thread is not blocked ... call socket(2) and use poll(2) or select(2) to ... C++: PTHREAD_CANCEL_ASYNCHRONOUS and random crash - comp ...3) Disable asynchronous cancellation when you enter ... I'm writting a C/sockets client interface on ... 2004 6:10:26 ... bolt circle dia in the call out so that if the B.C ... Solaris Core --Signal 9 --not able to find anything useful - comp ...C++ wrapper for async socket calls. - comp.unix.programmer ... On a single core, poll is much easier to use. -- Ian Collins ... Also, this meant being able to use a ... using gfortran to call windows api functions - comp.lang.fortran ...Sockets in gfortran? - comp.lang.fortran... char * msg, int n); /* Wrapper to call fortran ... in C, and calling the C socket functions from Fortran turns ... Open Source PDF Tools in C/C++ - comp.text.pdfAre there any open source PDF C ... for any other language, and call it from C/C++ using some distributed technology such as sockets ... URL below) which is a thinnish wrapper ... C++ wrapper for async socket calls. - comp.unix.programmer ...All, I am looking for a C++ wrapper over BSD socket library. I plan to use socket i/o during telecom call processing in a thread so that thread is ... Socket Asynchronous Calls | Dr Dobb'sSocket Asynchronous Calls. By Richard Grimes , September 10, 2004. The NetworkStream class is a wrapper around the Socket class. Accessing the Windows asynchronous ... 7/20/2012 6:54:59 AM
|