2 ==================================================================================
3 Copyright (c) 2019 Nokia
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
21 Mnemonic rmr_get_rcvfd.3.xfm
22 Abstract The manual page for the rmr_get_rcvfd function.
23 Author E. Scott Daniels
27 .** if formatting with tfm, the roff.im will cause roff output to be generated
28 .** if formatting with pfm, then pretty postscript will be generated
31 .im &{lib}/generic_ps.im
33 .gv e OUTPUT_RST use_rst
43 &h1(RMR Library Functions)
52 void* rmr_get_rcvfd( void* ctx )
58 The &cw(rmr_get_rcvfd) function returns a file descriptor which may be given to epoll_wait()
59 by an application that wishes to use event poll in a single thread rather than block
60 on the arrival of a message via calls to rmr_rcv_msg().
61 When epoll_wait() indicates that this file descriptor is ready, a call to rmr_rcv_msg()
62 will not block as at least one message has been received.
65 The context (ctx) pointer passed in is the pointer returned by the call to rmr_init().
68 &bold(NOTE^:) There is no support for epoll in Nanomsg, thus his function is only supported
69 when linking with the NNG version of RMr and the file descriptor returned when using the
70 Nanomsg verfsion will always return an error.
74 The &cw(rmr_get_rcvfd) function returns a file descriptor greater or equal to 0 on success
76 If this function is called from a user application linked against the Nanomsg RMr library,
77 calls will always return -1 with errno set to EINVAL.
80 The following error values are specifically set by this RMR function. In some cases the
81 error message of a system call is propagated up, and thus this list might be incomplete.
83 &beg_dlist(.75i : ^&bold_font )
84 &di(EINVAL) The use of this function is invalid in this environment.
88 The following short code bit illustrates the use of this function. Error checking has
89 been omitted for clarity.
95 #include <sys/epoll.h>
99 int rcv_fd; // pollable fd
100 void* mrc; //msg router context
101 struct epoll_event events[10]; // support 10 events to poll
102 struct epoll_event epe; // event definition for event to listen to
104 rmr_mbuf_t* msg = NULL;
108 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
109 rcv_fd = rmr_get_rcvfd( mrc );
111 ep_fd = epoll_create1( 0 ); // initialise epoll environment
112 epe.events = EPOLLIN;
113 epe.data.fd = rcv_fd;
114 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
117 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
118 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
119 if( events[i].data.fd == rcv_fd ) { // RMr has something
120 msg = rmr_rcv_msg( mrc, msg );
122 // do something with msg
126 // check for other ready fds....