X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=mISDN.cpp;h=dc6be83eb57d688dd2db5ef2a830f02c2d65bee6;hp=3e7751eae14aeabde5acb89a338eb77cc6503354;hb=5b5923141c3ac53d3e63395d9197080d087342f3;hpb=b0bd74e35e935aa976b68c594def4e8d2c22ef95 diff --git a/mISDN.cpp b/mISDN.cpp index 3e7751e..dc6be83 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -12,11 +12,9 @@ #include "main.h" #include "myisdn.h" -extern "C" { -#define MISDN_OLD_AF_COMPATIBILITY 1 -#include -} -#include +#include +int __af_isdn = MISDN_AF_ISDN; +#include #undef offsetof #ifdef __compiler_offsetof @@ -56,12 +54,10 @@ int mISDN_initialize(void) { char filename[256]; - init_af_isdn(); - /* try to open raw socket to check kernel */ mISDNsocket = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE); if (mISDNsocket < 0) { - fprintf(stderr, "Cannot open mISDN due to '%s'. (Does your Kernel support socket based mISDN?)\n", strerror(errno)); + fprintf(stderr, "Cannot open mISDN due to '%s'. (Does your Kernel support socket based mISDN? Protocol family is %d.)\n", strerror(errno), PF_ISDN); return(-1); } @@ -82,7 +78,7 @@ int mISDN_initialize(void) if (pipe(upqueue_pipe) < 0) FATAL("Failed to open pipe\n"); - memset(&upqueue_fd, 0, sizeof(upqueue_fd.fd)); + memset(&upqueue_fd, 0, sizeof(upqueue_fd)); upqueue_fd.fd = upqueue_pipe[0]; register_fd(&upqueue_fd, LCR_FD_READ, mISDN_upqueue, NULL, 0); @@ -1832,10 +1828,14 @@ static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, i struct mbuffer *mb; struct l3_msg *l3m; char byte; + int ret; /* unset global semaphore */ - read(fd->fd, &byte, 1); upqueue_avail = 0; + // with a very small incident, upqueue_avail may be set by mISDN thread and + // another byte may be sent to the pipe, which causes a call to this function + // again with nothing in the upqueue. this is no problem. + ret = read(fd->fd, &byte, 1); /* process all ports */ mISDNport = mISDNport_first; @@ -2060,9 +2060,13 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3 l3m->pid = pid; mqueue_tail(&mISDNport->upqueue, mb); if (!upqueue_avail) { + // multiple threads may cause multiple calls of this section, but this + // results only in multiple processing of the upqueue read. + // this is no problem. upqueue_avail = 1; char byte = 0; - write(upqueue_pipe[1], &byte, 1); + int ret; + ret = write(upqueue_pipe[1], &byte, 1); } return 0; }