49 if (fd < 0)
return -EINVAL;
53 #ifdef ENABLE_DEBUG_MSGS 54 unsigned char *msg_ = msg;
58 n = write(fd, msg, m);
60 if (EINTR == errno )
continue;
61 if (errno != EWOULDBLOCK && errno != EAGAIN)
return -errno;
67 n = fcntl(fd, F_GETFL, 0);
68 if (-1 == n)
return -errno;
69 if (0 == (n & O_NONBLOCK)) {
71 dbg(ctx,
"Short write: %d bytes written instead of %d\n", (
int)(size - m), (
int)size);
79 n = select(fd, NULL, &myset, NULL, &to);
83 if (n < 0 && errno == EINTR)
continue;
85 if (n < 0 && m == size)
return -errno;
87 dbg(ctx,
"Write error %d: %d bytes written, instead of %d\n", -errno, (
int)(size-m), (
int)size);
91 if (n == 0 && m == size) {
96 dbg(ctx,
"Short write (timeout): %d bytes written instead of %d\n", (
int)(size-m), (
int) size);
101 #ifdef ENABLE_DEBUG_MSGS 103 unsigned int j = 0, k;
107 for (k = 0; k < size; k++, j++) {
109 dbg(ctx,
"> %s\n",buf);
113 sprintf(buf + strlen(buf),
" 0x%02x,", msg_[k]);
115 dbg(ctx,
"> %s\n",buf);
126 if (fd < 0)
return -EINVAL;
130 #ifdef ENABLE_DEBUG_MSGS 131 unsigned char *msg_ = msg;
135 n = read(fd, msg, m);
137 if(errno == EINTR)
continue;
138 if(errno != EWOULDBLOCK && errno != EAGAIN)
return -errno;
141 if (n == 0)
return size-m;
148 n = fcntl(fd, F_GETFL, 0);
149 if (-1 == n)
return -errno;
150 if (0 == (n & O_NONBLOCK)) {
152 dbg(ctx,
"Short read: %d instead of %d\n", (
int)(size-m), (
int) size);
159 i = select(fd, &myset, NULL, NULL, &to);
163 if (i < 0 && errno == EINTR)
continue;
165 if (i < 0 && m == size)
return -errno;
168 dbg(ctx,
"Read error %d: %d bytes read, instead of %d\n", -errno, (
int)(size-m), (
int)size);
172 if (i == 0 && m == size) {
178 dbg(ctx,
"Short read (timeout): %d instead of %d\n", (
int)(size-m), (
int)size);
183 #ifdef ENABLE_DEBUG_MSGS 185 unsigned int j = 0, k;
189 for (k = 0; k < size-m; k++, j++) {
191 dbg(ctx,
"< %s\n",buf);
195 sprintf(buf + strlen(buf),
" 0x%02x,", msg_[k]);
197 dbg(ctx,
"< %s\n",buf);
205 if (!ctx)
return -EINVAL;
211 if (!ctx)
return -EINVAL;
216 if (!ctx)
return -EINVAL;
228 return ctx->iotimeout;
LIGHTIFY_EXPORT int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
LIGHTIFY_EXPORT int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv)
int write_to_socket(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
LIGHTIFY_EXPORT int lightify_skt_getfd(struct lightify_ctx *ctx)
LIGHTIFY_EXPORT struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx)
int read_from_socket(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
int lightify_get_log_priority(struct lightify_ctx *ctx)
struct lightify_ctx * ctx