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 The &cw(rmr_get_rcvfd) function returns a file descriptor greater or equal to 0 on success
61 The following error values are specifically set by this RMR function. In some cases the
62 error message of a system call is propagated up, and thus this list might be incomplete.
64 &beg_dlist(.75i : ^&bold_font )
65 &di(EINVAL) The use of this function is invalid in this environment.
69 The following short code bit illustrates the use of this function. Error checking has
70 been omitted for clarity.
76 #include <sys/epoll.h>
80 int rcv_fd; // pollable fd
81 void* mrc; //msg router context
82 struct epoll_event events[10]; // support 10 events to poll
83 struct epoll_event epe; // event definition for event to listen to
85 rmr_mbuf_t* msg = NULL;
88 int norm_msg_size = 1500; // 95% messages are less than this
90 mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
91 rcv_fd = rmr_get_rcvfd( mrc );
93 ep_fd = epoll_create1( 0 ); // initialise epoll environment
96 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
99 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
100 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
101 if( events[i].data.fd == rcv_fd ) { // RMR has something
102 msg = rmr_rcv_msg( mrc, msg );
104 // do something with msg
108 // check for other ready fds....