Browse Source

Move failure warnings into write_length, importing source details and adding info about type of failure

master
Con Kolivas 10 years ago
parent
commit
f791495889
  1. 25
      src/libckpool.c
  2. 3
      src/libckpool.h

25
src/libckpool.c

@ -1003,20 +1003,27 @@ out:
return ret; return ret;
} }
int write_length(int sockd, const void *buf, int len) int _write_length(int sockd, const void *buf, int len, const char *file, const char *func, const int line)
{ {
int ret, ofs = 0; int ret, ofs = 0;
if (unlikely(len < 1)) { if (unlikely(len < 1)) {
LOGWARNING("Invalid write length of %d requested in write_length", len); LOGWARNING("Invalid write length of %d requested in write_length from %s %s:%d",
len, file, func, line);
return -1; return -1;
} }
if (unlikely(sockd < 0)) if (unlikely(sockd < 0)) {
LOGWARNING("Attempt to write to invalidated sock in write_length from %s %s:%d",
file, func, line);
return -1; return -1;
}
while (len) { while (len) {
ret = write(sockd, buf + ofs, len); ret = write(sockd, buf + ofs, len);
if (unlikely(ret < 0)) if (unlikely(ret < 0)) {
LOGERR("Failed to write %d bytes in write_length from %s %s:%d",
len, file, func, line);
return -1; return -1;
}
ofs += ret; ofs += ret;
len -= ret; len -= ret;
} }
@ -1049,10 +1056,9 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu
LOGERR("Select1 failed in send_unix_msg (%d)", ern); LOGERR("Select1 failed in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = write_length(sockd, &msglen, 4); ret = _write_length(sockd, &msglen, 4, file, func, line);
if (unlikely(ret < 4)) { if (unlikely(ret < 4)) {
ern = errno; LOGERR("Failed to write 4 byte length in send_unix_msg");
LOGERR("Failed to write 4 byte length in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = wait_write_select(sockd, 5); ret = wait_write_select(sockd, 5);
@ -1061,10 +1067,9 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu
LOGERR("Select2 failed in send_unix_msg (%d)", ern); LOGERR("Select2 failed in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = write_length(sockd, buf, len); ret = _write_length(sockd, buf, len, file, func, line);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
ern = errno; LOGERR("Failed to write %d bytes in send_unix_msg", len);
LOGERR("Failed to write %d bytes in send_unix_msg (%d)", len, ern);
goto out; goto out;
} }
retval = true; retval = true;

3
src/libckpool.h

@ -499,7 +499,8 @@ char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, co
#define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__) #define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__)
#define recv_unix_msg_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__) #define recv_unix_msg_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__)
int wait_write_select(int sockd, float timeout); int wait_write_select(int sockd, float timeout);
int write_length(int sockd, const void *buf, int len); #define write_length(sockd, buf, len) _write_length(sockd, buf, len, __FILE__, __func__, __LINE__)
int _write_length(int sockd, const void *buf, int len, const char *file, const char *func, const int line);
bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line); bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line);
#define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, __FILE__, __func__, __LINE__) #define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, __FILE__, __func__, __LINE__)
bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, const char *func, const int line); bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, const char *func, const int line);

Loading…
Cancel
Save