|
version 1.18.4.1, 2012/11/16 13:14:11
|
version 1.20, 2012/12/19 11:03:04
|
|
Line 645 io_gethostbyname(const char *psHost, u_short port, io_
|
Line 645 io_gethostbyname(const char *psHost, u_short port, io_
|
| * |
* |
| * @a = 1st address |
* @a = 1st address |
| * @b = 2nd address |
* @b = 2nd address |
| |
* @p = compare and ports, if family is AF_INET or AF_INET6 |
| * return: 0 is equal or !=0 is different |
* return: 0 is equal or !=0 is different |
| */ |
*/ |
| int |
int |
| io_addrcmp(io_sockaddr_t * __restrict a, io_sockaddr_t * __restrict b) | io_addrcmp(io_sockaddr_t * __restrict a, io_sockaddr_t * __restrict b, int p) |
| { |
{ |
| if (a && b && a->sa.sa_family == b->sa.sa_family) |
if (a && b && a->sa.sa_family == b->sa.sa_family) |
| switch (a->sa.sa_family) { |
switch (a->sa.sa_family) { |
| case AF_LOCAL: |
case AF_LOCAL: |
| return strcmp(a->sun.sun_path, b->sun.sun_path); |
return strcmp(a->sun.sun_path, b->sun.sun_path); |
| case AF_INET: |
case AF_INET: |
| return memcmp(&a->sin.sin_addr, &b->sin.sin_addr, | if (p && (a->sin.sin_port - b->sin.sin_port)) |
| sizeof a->sin.sin_addr); | return (int) !!(a->sin.sin_port - b->sin.sin_port); |
| | else |
| | return memcmp(&a->sin.sin_addr, &b->sin.sin_addr, |
| | sizeof a->sin.sin_addr); |
| case AF_INET6: |
case AF_INET6: |
| return memcmp(&a->sin6.sin6_addr, &b->sin6.sin6_addr, | if (p && (a->sin6.sin6_port - b->sin6.sin6_port)) |
| sizeof a->sin6.sin6_addr); | return (int) !!(a->sin6.sin6_port - b->sin6.sin6_port); |
| | else |
| | return memcmp(&a->sin6.sin6_addr, &b->sin6.sin6_addr, |
| | sizeof a->sin6.sin6_addr); |
| case AF_LINK: |
case AF_LINK: |
| return memcmp(&a->sdl.sdl_data, &b->sdl.sdl_data, |
return memcmp(&a->sdl.sdl_data, &b->sdl.sdl_data, |
| sizeof a->sdl.sdl_data); |
sizeof a->sdl.sdl_data); |
|
Line 680 io_usleep(u_int usec)
|
Line 687 io_usleep(u_int usec)
|
| struct timeval tv = { (time_t) (usec / 1000000), (long) (usec % 1000000) }; |
struct timeval tv = { (time_t) (usec / 1000000), (long) (usec % 1000000) }; |
| |
|
| return select(0, NULL, NULL, NULL, &tv); |
return select(0, NULL, NULL, NULL, &tv); |
| |
} |
| |
|
| |
/* |
| |
* io_AV2Path() - Attribute/Value pair store to file |
| |
* |
| |
* @csPath = Directory |
| |
* @csAttr = Attribute |
| |
* @csVal = Value |
| |
* @update = Update if a/v exists |
| |
* @perm = File permissions, if =0 set default perm=0600 |
| |
* return: -1 error or >-1 written bytes |
| |
*/ |
| |
int |
| |
io_AV2Path(const char *csPath, const char *csAttr, const char *csVal, |
| |
int update, int perm) |
| |
{ |
| |
int fd, wlen = 0; |
| |
char szFile[MAXPATHLEN]; |
| |
|
| |
if (!csAttr) |
| |
return -1; |
| |
else |
| |
memset(szFile, 0, sizeof szFile); |
| |
snprintf(szFile, sizeof szFile, "%s/%s.av", csPath ? csPath : ".", csAttr); |
| |
|
| |
wlen = O_CREAT | O_WRONLY; |
| |
if (!update) |
| |
wlen |= O_EXCL; |
| |
fd = open(szFile, wlen, perm ? perm : 0600); |
| |
if (fd == -1) { |
| |
LOGERR; |
| |
return -1; |
| |
} else |
| |
wlen ^= wlen; |
| |
|
| |
if (csVal) |
| |
if ((wlen = write(fd, csVal, strlen(csVal))) == -1) { |
| |
LOGERR; |
| |
close(fd); |
| |
unlink(szFile); |
| |
return -1; |
| |
} |
| |
|
| |
close(fd); |
| |
return wlen; |
| |
} |
| |
|
| |
/* |
| |
* io_Path2AV() - Get stored Attribute/Value |
| |
* |
| |
* @csPath = Directory |
| |
* @csAttr = Attribute |
| |
* @psVal = Value |
| |
* @valLen = Value length |
| |
* @del = Delete a/v pair after read |
| |
* return: -1 error or >-1 readed bytes |
| |
*/ |
| |
int |
| |
io_Path2AV(const char *csPath, const char *csAttr, char *psVal, int valLen, int del) |
| |
{ |
| |
int fd, rlen = 0; |
| |
char szFile[MAXPATHLEN]; |
| |
|
| |
if (!csAttr) |
| |
return -1; |
| |
else |
| |
memset(szFile, 0, sizeof szFile); |
| |
snprintf(szFile, sizeof szFile, "%s/%s.av", csPath ? csPath : ".", csAttr); |
| |
|
| |
if (psVal && valLen) { |
| |
fd = open(szFile, O_RDONLY); |
| |
if (fd == -1) { |
| |
LOGERR; |
| |
return -1; |
| |
} else |
| |
rlen ^= rlen; |
| |
|
| |
memset(psVal, 0, valLen); |
| |
rlen = read(fd, psVal, valLen - 1); |
| |
if (rlen == -1) { |
| |
LOGERR; |
| |
close(fd); |
| |
return -1; |
| |
} |
| |
|
| |
close(fd); |
| |
} |
| |
|
| |
if (del) |
| |
unlink(szFile); |
| |
return rlen; |
| } |
} |