* Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: unix.c,v 1.3 2002-07-03 13:36:55 adam Exp $
+ * $Id: unix.c,v 1.7 2002-09-25 12:37:07 adam Exp $
* UNIX socket COMSTACK. By Morten Bøgeskov.
*/
#ifndef WIN32
/* Chas added the following, so we get the definition of completeBER */
#include <yaz/odr.h>
+#ifndef YAZ_SOCKLEN_T
+#define YAZ_SOCKLEN_T int
+#endif
+
int unix_close(COMSTACK h);
int unix_put(COMSTACK h, char *buf, int size);
int unix_get(COMSTACK h, char **buf, int *bufsize);
char *unix_addrstr(COMSTACK h);
void *unix_straddr(COMSTACK h, const char *str);
+#ifndef SUN_LEN
+#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+ + strlen ((ptr)->sun_path))
+#endif
#if 0
#define TRC(x) x
#else
r = connect(h->iofile, (struct sockaddr *) add, SUN_LEN(add));
if (r < 0)
{
- if (errno == EINPROGRESS)
+ if (yaz_errno() == EINPROGRESS)
{
h->event = CS_CONNECT;
h->state = CS_ST_CONNECTING;
int socket_out = -1;
if(! S_ISSOCK(stat_buf.st_mode)) {
h->cerrno = CSYSERR;
- errno = EEXIST; /* Not a socket (File exists) */
+ yaz_set_errno(EEXIST); /* Not a socket (File exists) */
return -1;
}
if((socket_out = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
socket_unix.sun_family = AF_UNIX;
strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path));
if(connect(socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix)) < 0) {
- if(errno == ECONNREFUSED) {
+ if(yaz_errno() == ECONNREFUSED) {
TRC (fprintf (stderr, "Socket exists but nobody is listening\n"));
} else {
h->cerrno = CSYSERR;
} else {
close(socket_out);
h->cerrno = CSYSERR;
- errno = EADDRINUSE;
+ yaz_set_errno(EADDRINUSE);
return -1;
}
unlink(path);
void *cd)
{
struct sockaddr_un addr;
-#ifdef __cplusplus
- socklen_t len = SUN_LEN(&addr);
-#else
- int len = SUN_LEN(&addr);
-#endif
+ YAZ_SOCKLEN_T len = SUN_LEN(&addr);
TRC(fprintf(stderr, "unix_listen pid=%d\n", getpid()));
if (h->state != CS_ST_IDLE)
if (h->newfd < 0)
{
if (
- errno == EWOULDBLOCK
+ yaz_errno() == EWOULDBLOCK
#ifdef EAGAIN
#if EAGAIN != EWOULDBLOCK
- || errno == EAGAIN
+ || yaz_errno() == EAGAIN
#endif
#endif
)
TRC(fprintf(stderr, " recv res=%d, hasread=%d\n", res, hasread));
if (res < 0)
{
- if (errno == EWOULDBLOCK
+ if (yaz_errno() == EWOULDBLOCK
#ifdef EAGAIN
#if EAGAIN != EWOULDBLOCK
- || errno == EAGAIN
+ || yaz_errno() == EAGAIN
#endif
#endif
- || errno == EINPROGRESS
+ || yaz_errno() == EINPROGRESS
)
{
h->io_pending = CS_WANT_READ;
break;
}
- else if (errno == 0)
+ else if (yaz_errno() == 0)
continue;
else
return -1;
)) < 0)
{
if (
- errno == EWOULDBLOCK
+ yaz_errno() == EWOULDBLOCK
#ifdef EAGAIN
#if EAGAIN != EWOULDBLOCK
- || errno == EAGAIN
+ || yaz_errno() == EAGAIN
#endif
#endif
)