30 #include <sys/eventfd.h>
31 #include <sys/ioctl.h>
32 #include <sys/types.h>
43 #define DBG(args...) //fprintf(stderr, args)
46 #define LIKELY(x) (__builtin_expect(!!(x), 1))
47 #define UNLIKELY(x) (__builtin_expect(!!(x), 0))
50 #define UNLIKELY(x) (x)
53 #define SBDN RTM_T_Device::MAXBUF
63 #define TEST_NULLPTR(ptr) do{if UNLIKELY(!ptr){fprintf(stderr, "NULL pointer error");return -1;}}while(0)
64 #define ERROR_START(errorcode, message) do{\
65 perror(message " error");\
66 if (stream && stream->dev)\
74 #define CHECK(i) (pfds[i].revents & POLLIN)
75 #define CHECK_STOP CHECK(0)
76 #define CHECK_FD CHECK(1)
80 const int fd =
stream->dev->getDeviceHandle();
81 struct pollfd pfds[2] = {
82 { .fd=
stream->stop, .events=POLLIN },
83 { .fd=fd, .events=POLLIN },
85 const int ready = poll(pfds, 2, -1);
91 DBG(
"nread=%d\n", nread);
111 perror(
"poll error");
125 fprintf(stderr,
"ERROR NOT IBUF_MAGIC %08x %08x\n",
132 static inline int release_buffer(
void *
const handle,
const int bufno)
134 return write(((
STREAM_P)handle)->dev->getDeviceHandle(), &bufno,
sizeof(
int)) !=
sizeof(int);
143 if UNLIKELY((
stream->stop = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0)
166 const uint64_t value = 1;
167 return write(
stream->stop, &value,
sizeof(value)) !=
sizeof(value);
189 if (fetch_buffers(
stream))
191 perror(
"fetch error");
199 const int bufno = get_bufno(&
stream->sbd[
stream->ibuf++]);
201 memcpy(buf,
stream->dev->getHostBufferMapping(bufno), buflen);
202 return release_buffer(
stream, bufno);