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
28 .im &{lib}/man/setup.im
32 &h1(RMR Library Functions)
41 void* rmr_get_rcvfd( void* ctx )
47 The &cw(rmr_get_rcvfd) function returns a file descriptor which may be given to epoll_wait()
48 by an application that wishes to use event poll in a single thread rather than block
49 on the arrival of a message via calls to rmr_rcv_msg().
50 When epoll_wait() indicates that this file descriptor is ready, a call to rmr_rcv_msg()
51 will not block as at least one message has been received.
54 The context (ctx) pointer passed in is the pointer returned by the call to rmr_init().
57 &bold(NOTE^:) There is no support for epoll in Nanomsg, thus his function is only supported
58 when linking with the NNG version of RMr and the file descriptor returned when using the
59 Nanomsg verfsion will always return an error.
63 The &cw(rmr_get_rcvfd) function returns a file descriptor greater or equal to 0 on success
65 If this function is called from a user application linked against the Nanomsg RMr library,
66 calls will always return -1 with errno set to EINVAL.
69 The following error values are specifically set by this RMR function. In some cases the
70 error message of a system call is propagated up, and thus this list might be incomplete.
72 &beg_dlist(.75i : ^&bold_font )
73 &di(EINVAL) The use of this function is invalid in this environment.
77 The following short code bit illustrates the use of this function. Error checking has
78 been omitted for clarity.
84 #include <sys/epoll.h>
88 int rcv_fd; // pollable fd
89 void* mrc; //msg router context
90 struct epoll_event events[10]; // support 10 events to poll
91 struct epoll_event epe; // event definition for event to listen to
93 rmr_mbuf_t* msg = NULL;
97 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
98 rcv_fd = rmr_get_rcvfd( mrc );
100 ep_fd = epoll_create1( 0 ); // initialise epoll environment
101 epe.events = EPOLLIN;
102 epe.data.fd = rcv_fd;
103 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
106 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
107 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
108 if( events[i].data.fd == rcv_fd ) { // RMr has something
109 msg = rmr_rcv_msg( mrc, msg );
111 // do something with msg
115 // check for other ready fds....