Commit b74c67c0 authored by deuce's avatar deuce
Browse files

Move LOG_* into xpdev/gen_defs.h

Add retry_bind() function (exteded bind() function that will retry a number of times)
parent b048f5de
......@@ -796,22 +796,6 @@ enum { /* Values of mode for userlist function */
#define BO_OPENFILE 0 /* Backout types */
#if defined(__unix__)
#include <syslog.h>
#else
/*
* log priorities (copied from BSD syslog.h)
*/
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
#endif
/**********/
/* Macros */
/**********/
......
......@@ -279,5 +279,21 @@ typedef struct {
/********************************/
#define COUNT_LIST_ITEMS(list,i) { i=0; if(list!=NULL) while(list[i]!=NULL) i++; }
#if defined(__unix__)
#include <syslog.h>
#else
/*
* log priorities (copied from BSD syslog.h)
*/
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
#endif
#endif /* Don't add anything after this #endif statement */
......@@ -42,7 +42,7 @@
#include <string.h>
#include "genwrap.h" /* SLEEP */
#include "gen_defs.h" /* BOOL */
#include "gen_defs.h" /* BOOL/LOG_WARNING */
#include "sockwrap.h" /* sendsocket */
#include "filewrap.h" /* filelength */
......@@ -230,3 +230,33 @@ BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout)
return(FALSE);
}
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen, int retries, int wait_secs, int *(lprintf)(int level, char *fmt, ...))
{
int result=-1;
int i;
for(i=0;i<=retries;i++) {
result = bind(s,addr,addrlen);
if(result != 0) {
if(lprintf!=NULL) {
if(addr->sa_family==AF_INET) {
lprintf(LOG_WARNING,"%04d !WARNING %d (%d) error binding socket to port %d"
,s, result, ERROR_VALUE,((SOCKADDR_IN *)(addr))->sin_port);
}
else {
lprintf(LOG_WARNING,"%04d !WARNING %d (%d) error binding socket"
,s, result, ERROR_VALUE);
}
}
if(i<retries) {
if(lprintf!=NULL)
lprintf(LOG_WARNING,"%04d Will retry in %d seconds",s ,wait_secs);
SLEEP(wait_secs*1000);
}
}
else
break;
}
return(result);
}
......@@ -155,6 +155,7 @@ extern "C" {
int sendfilesocket(int sock, int file, long *offset, long count);
int recvfilesocket(int sock, int file, long *offset, long count);
BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen, int retries, int wait_secs, int *(lprintf)(int level, char *fmt, ...));
#ifdef __cplusplus
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment