Пример #1
0
double
__jn( int n, double x )
{
int i;
double a, b, temp;
double	z;
double zsq, t;
double result;
#ifdef _CALL_MATHERR
struct exception	exstruct;
#endif

	if( x != x )
	{
		/* arg is NaN */

#ifdef _CALL_MATHERR

		exstruct.type = DOMAIN;
		exstruct.name = "jn";
		exstruct.arg1 = n;
		exstruct.arg2 = x;
		exstruct.retval = Qnan.d;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "domain error in jn\n");
			SETERRNO(EDOM);
		}

		return ( exstruct.retval );
#else
		NAN_SETERRNO(EDOM);

		return ( Qnan.d );
#endif
	}

        if ( fabs(x) >= Twop49.d )
	{
#ifdef _CALL_MATHERR

		exstruct.type = TLOSS;
		exstruct.name = "jn";
		exstruct.arg1 = n;
		exstruct.arg2 = x;
		exstruct.retval = 0.0;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "total loss of significance \
error in jn\n");
			SETERRNO(ERANGE);
		}
Пример #2
0
DWORD OutputMonitor::__ProcessImpl()
{
    DWORD dret;
    int ret;
    HANDLE hWaitHandle[2];

    hWaitHandle[0] = this->m_hDBWinDataReady;
    hWaitHandle[1] = this->m_ThreadControl.exitevt;

    /*make sure buffer ready for client handle*/
    SetEvent(this->m_hDBWinBufferReady);

    while(this->m_ThreadControl.running) {
        dret = WaitForMultipleObjectsEx(2,hWaitHandle,FALSE,INFINITE,TRUE);
        if(dret == WAIT_OBJECT_0) {
            ret = this->__HandleBufferIn();
            if(ret < 0) {
                ret = GETERRNO();
                dret = -ret;
                goto out;
            }
        } else if(dret == WAIT_FAILED || dret == WAIT_ABANDONED) {
            ret = GETERRNO();
            dret = -ret;
            goto out;
        }
    }

    ret = 0;

out:
    this->m_ThreadControl.exited = 1;
    SETERRNO(ret);
    return dret;
}
Пример #3
0
/**
 *  @brief      Retrieves address/port info for the local socket.
 *
 *  @param      pAddress
 *                  Buffer to hold the address.
 *  @param      pAddrLen
 *                  Maximum size of pAddress.
 *  @param      pPort
 *                  Port number opened locally.
 *------------------------------------------------------------------*/
bool VSocket::GetSockName(char *pAddress, int pAddrLen,
		VUSHORT *pPort /*=NULL*/)
{
	bool        vRetval = true;
	VSockAddr   vAddr;
	socklen_t   vSAlen = sizeof(vAddr);

	BEG_FUNC("GetSockName")("%p, %d, %d", pAddress, pAddrLen, pPort);

	/* Obtain local connection info */
	if (getsockname(mHandle, (struct sockaddr*)&vAddr, &vSAlen) != -1) {
		if (pPort != NULL)
			*pPort = vAddr.GetPort();
		if (pAddress != NULL) {
			memset(pAddress, 0, pAddrLen);
			if (vAddr.GetAddr() != NULL)
				strncpy(pAddress, vAddr.GetAddr(), pAddrLen);
			else
				strncpy(pAddress, "No address", pAddrLen-1);
		}
	} else {
		SETERRNO();
		mError = errno;
		vRetval = false;
	}

	return END_FUNC(vRetval);
}
Пример #4
0
SSize_t PerlIOmIRC_read( pTHX_ PerlIO *f, void *vbuf, Size_t count ) {
    STDCHAR *buf = ( STDCHAR * ) vbuf;
    if ( f ) {
        if ( !( PerlIOBase( f )->flags & PERLIO_F_CANREAD ) ) {
            PerlIOBase( f )->flags |= PERLIO_F_ERROR;
            SETERRNO( EBADF, SS_IVCHAN );
            return 0;
        }
        while ( count > 0 ) {
get_cnt: {
                SSize_t avail = PerlIO_get_cnt( f );
                SSize_t take = 0;
                if ( avail > 0 )
                    take = ( ( SSize_t )count < avail ) ? ( SSize_t )count : avail;
                if ( take > 0 ) {
                    STDCHAR *ptr = PerlIO_get_ptr( f );
                    Copy( ptr, buf, take, STDCHAR );
                    PerlIO_set_ptrcnt( f, ptr + take, ( avail -= take ) );
                    count -= take;
                    buf += take;
                    if ( avail == 0 )  /* set_ptrcnt could have reset avail */
                        goto get_cnt;
                }
                if ( count > 0 && avail <= 0 ) {
                    if ( PerlIO_fill( f ) != 0 )
                        break;
                }
            }
        }
        return ( buf - ( STDCHAR * ) vbuf );
    }
    return 0;
}
Пример #5
0
IV
PerlIOScalar_seek(pTHX_ PerlIO * f, Off_t offset, int whence)
{
    PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar);
    STRLEN oldcur = SvCUR(s->var);
    STRLEN newlen;
    switch (whence) {
    case SEEK_SET:
	s->posn = offset;
	break;
    case SEEK_CUR:
	s->posn = offset + s->posn;
	break;
    case SEEK_END:
	s->posn = offset + SvCUR(s->var);
	break;
    }
    if (s->posn < 0) {
        if (ckWARN(WARN_LAYER))
	    Perl_warner(aTHX_ packWARN(WARN_LAYER), "Offset outside string");
	SETERRNO(EINVAL, SS_IVCHAN);
	return -1;
    }
    newlen = (STRLEN) s->posn;
    if (newlen > oldcur) {
	(void) SvGROW(s->var, newlen);
	Zero(SvPVX(s->var) + oldcur, newlen - oldcur, char);
	/* No SvCUR_set(), though.  This is just a seek, not a write. */
    }
Пример #6
0
int OutputMonitor::Start()
{
    int started = 0;
    int ret;

    started = this->__SetStarted(1);
    if(started > 0) {
        return 0;
    }

    ret = this->__CreateBuffers();
    if(ret < 0) {
        ret = GETERRNO();
        this->Stop();
        SETERRNO(ret);
        return -ret;
    }

    /*now we should give it started*/
    ret = this->__CreateMutexEvent();
    if(ret < 0) {
        ret = GETERRNO();
        this->Stop();
        SETERRNO(ret);
        return -ret;
    }

    ret = this->__MapBuffer();
    if(ret < 0) {
        ret = GETERRNO();
        this->Stop();
        SETERRNO(ret);
        return -ret;
    }

    ret = StartThreadControl(&(this->m_ThreadControl),OutputMonitor::__ProcessMonitor,this,1);
    if(ret < 0) {
        ret = GETERRNO();
        this->Stop();
        SETERRNO(ret);
        return -ret;
    }

    return 0;
}
Пример #7
0
static IV
PerlIOFlock_pushed(pTHX_ PerlIO* fp, const char* mode, SV* arg,
		PerlIO_funcs* tab){

	int lock_mode;
	int fd;
	int ret;

	PERL_UNUSED_ARG(mode);
	PERL_UNUSED_ARG(tab);

	if(!PerlIOValid(fp)){
		SETERRNO(EBADF, SS_IVCHAN);
		return -1;
	}

	lock_mode = IOLflag(fp, PERLIO_F_CANWRITE) ? LOCK_EX : LOCK_SH;

	if(arg && SvOK(arg)){
		const char* const blocking = SvPV_nolen_const(arg);

		if(strEQ(blocking, "blocking")){
			/* noop */
		}
		else if(strEQ(blocking, "non-blocking")
			|| strEQ(blocking, "LOCK_NB")){
			lock_mode |= LOCK_NB;
		}
		else{
			Perl_croak(aTHX_ "Unrecognized :flock handler '%s' "
				"(it must be 'blocking' or 'non-blocking')",
					blocking);
		}
	}

	fd  = PerlIO_fileno(fp);
	if(fd == -1){ /* :scalar, :dir, etc. */
		return 0; /* success */
	}

	PerlIO_flush(fp);
	ret = PerlLIO_flock(fd, lock_mode);

	PerlIO_debug(STRINGIFY(FLOCK) "(%d, %s) -> %d\n", fd,
		(  lock_mode == (LOCK_SH)         ? "LOCK_SH"
		 : lock_mode == (LOCK_SH|LOCK_NB) ? "LOCK_SH|LOCK_NB"
		 : lock_mode == (LOCK_EX)         ? "LOCK_EX"
		 : lock_mode == (LOCK_EX|LOCK_NB) ? "LOCK_EX|LOCK_NB"
		 : "(UNKNOWN)" ),
		ret);

	return ret;
}
Пример #8
0
int OutputMonitor::__MapBuffer()
{
    int ret;

    assert(this->m_hDBWinMapBuffer == NULL);
    assert(this->m_pDBWinBuffer == NULL);

    if (this->m_GlobalWin32) {
        this->m_hDBWinMapBuffer = CreateMapFile("Global\\DBWIN_BUFFER", sizeof(DBWIN_BUFFER_t), 0);
    } else {
        this->m_hDBWinMapBuffer = CreateMapFile("DBWIN_BUFFER", sizeof(DBWIN_BUFFER_t), 0);
    }
    if(this->m_hDBWinMapBuffer == NULL) {
        if (this->m_GlobalWin32) {
            this->m_hDBWinMapBuffer = CreateMapFile("Global\\DBWIN_BUFFER", sizeof(DBWIN_BUFFER_t), 1);
        } else {
            this->m_hDBWinMapBuffer = CreateMapFile("DBWIN_BUFFER", sizeof(DBWIN_BUFFER_t), 1);
        }
        if(this->m_hDBWinMapBuffer == NULL) {
            ret = GETERRNO();
            goto fail;
        }
    }

    this->m_pDBWinBuffer = MapFileBuffer(this->m_hDBWinMapBuffer,sizeof(DBWIN_BUFFER_t));
    if(this->m_pDBWinBuffer == NULL) {
        ret = GETERRNO();
        goto fail;
    }

    SETERRNO(0);
    return 0;
fail:
    this->__UnMapBuffer();
    SETERRNO(ret);
    return -ret;
}
Пример #9
0
int OutputMonitor::GetBuffer(std::vector < PDBWIN_BUFFER_t > & pBuffers)
{
    int ret=0;
    PDBWIN_BUFFER_t pBuffer=NULL;

    if(pBuffers.size() != 0) {
        ret= ERROR_INVALID_PARAMETER;
        SETERRNO(ret);
        return -ret;
    }

    EnterCriticalSection(&(this->m_CS));
    if(this->m_Started== 0) {
        ret = -ERROR_BAD_ENVIRONMENT;
    } else {
        if(this->m_pAvailBuffers) {
            while(this->m_pAvailBuffers->size() > 0) {
                ret ++;
                assert(pBuffer == NULL);
                pBuffer = this->m_pAvailBuffers->at(0);
                this->m_pAvailBuffers->erase(this->m_pAvailBuffers->begin());
                pBuffers.push_back(pBuffer);
                pBuffer = NULL;
            }
        } else {
            ret = -ERROR_BAD_ENVIRONMENT;
        }
    }
    LeaveCriticalSection(&(this->m_CS));

    if(ret < 0) {
        SETERRNO(-ret);
    } else {
        SETERRNO(0);
    }
    return ret;
}
Пример #10
0
/**
 *  @brief      Begin listening for incoming client connections.
 *
 *  @param      pConnBacklog
 *                  Number of connections to allow in the
 *                  queue before rejecting.
 *------------------------------------------------------------------*/
bool VSocket::Listen(int pConnBacklog) {
	bool vRetval = true;

	BEG_FUNC("Listen")("%d", pConnBacklog);

	/*
	 * Already connected?
	 */
	if (mStatus == SS_CONNECTED) {
		VTRACE("Error-Socket already connected to %s\n",
				mEndPoint.GetAddr());
		mError = EISCONN;
		vRetval = false;
	}

	/*
	 * Socket initialized and bound?
	 */
	if (vRetval && mStatus != SS_ALLOCATED && mStatus != SS_BOUND) {
		VTRACE("Error-Socket not initialized or bound\n");
		mError = ENOTCONN;
		vRetval = false;
	}

	if (vRetval) {
		/*
		 * Try to put the socket into listening mode.
		 */
		if (listen(mHandle, pConnBacklog) == 0) {
			VTRACE("Socket successfully placed in listen mode.\n");
		} else {
			SETERRNO();
			mError = errno;
			vRetval = false;
			VTRACE("Error entering listening mode.  Error-%d:%s\n",
					mError, strerror(mError));
		}

		if (vRetval) {
			/*
			 * With the socket in listening mode, start the processing
			 * thread so we can be notified of incoming connections.
			 */
			mStatus = SS_LISTENING;
		}
	}

	return END_FUNC(vRetval);
}
Пример #11
0
/**
 *  @brief      Retrieves address/port info for the remote socket.
 *
 *  @param      pSockAddr
 *                  Structure pointer to hold the socket info.
 *  @param      pSockAddrLen
 *                  Pointer to the length pSockAddr.  On return,
 *                  pSockAddrLen will contain the actual size of
 *                  pSockAddr.
 *------------------------------------------------------------------*/
bool VSocket::GetPeerName(sockaddr *pSockAddr, socklen_t *pSockAddrLen) {
	bool vRetval = true;

	BEG_FUNC("GetPeerName")("%p, %p", pSockAddr, pSockAddrLen);

	*pSockAddrLen = sizeof(*pSockAddr);

	/* Obtain remote connection info */
	if (getpeername(mHandle, pSockAddr, pSockAddrLen) == 0) {
		SETERRNO();
		mError = errno;
	}

	return END_FUNC(vRetval);
}
Пример #12
0
int OutputMonitor::__InsertDbWinBuffer(PDBWIN_BUFFER_t pBuffer)
{
    int ret = -ERROR_BAD_ENVIRONMENT;
    EnterCriticalSection(&(this->m_CS));
    if(this->m_Started && this->m_pAvailBuffers) {
        this->m_pAvailBuffers->push_back(pBuffer);
        ret = 0;
    }
    LeaveCriticalSection(&(this->m_CS));

    if(ret >= 0) {
        SetEvent(this->m_hNotifyEvt);
    }
    SETERRNO(-ret);
    return ret;
}
Пример #13
0
/**
 *  @brief      Modifies one of the options associated with this socket.
 *
 *  @param      pOptName
 *                  Option whose value is to be modified.
 *  @param      pOptValue
 *                  Buffer that holds the new value.
 *  @param      pOptLen
 *                  Size of the pOptValue buffer.
 *  @param      pLevel
 *                  Level at which the option is defined.  The only
 *                  supported levels are SOL_SOCKET (default)
 *                  and IPPROTO_TCP.
 *------------------------------------------------------------------*/
bool VSocket::SetSockOpt(int pOptName, const void *pOptValue,
		int pOptLen, int pLevel /*=SOL_SOCKET*/) {
	bool vRetval = true;

	BEG_FUNC("SetSockOpt")("%d, %p, %d, %d", pOptName, pOptValue,
			pOptLen, pLevel);

	if (setsockopt(mHandle, pLevel, pOptName, (const char*)pOptValue,
				pOptLen) != 0) {
		SETERRNO();
		mError = errno;
		vRetval = false;
	}

	return END_FUNC(vRetval);
}
Пример #14
0
/**
 *  @brief      Shutdown communications on this socket.
 *
 *  @remarks    Called when the local side wishes to disconnect
 *              communications.  Optional parameter specifies which
 *              communications should be closed (send, recv, or both).
 *
 *  @param      pHow
 *                  Designates whether the socket should allow sends or
 *                  receives to finish.
 *
 *  @return     If the call is successful, returns 0.  Otherwise, -1 is
 *              returned, and a specific error code can be retrieved by
 *              calling GetLastError().
 *------------------------------------------------------------------*/
int VSocket::Shutdown(int pHow /*=SHUT_WR*/) {
	int vRetval = 0;

	BEG_FUNC("Shutdown")("%d", pHow);

	if (mHandle != -1) {
		vRetval = shutdown(mHandle, pHow);
		if (vRetval != 0) {
			SETERRNO();
			mError = errno;
			VTRACE("Error calling shutdown: %d:%s\n", errno, strerror(errno));
		}
	}

	return END_FUNC(vRetval);
}
Пример #15
0
/**
 *  @brief      Transmit data on this socket.
 *
 *  @remarks    Since we're in non-blocking mode, the number of bytes
 *              transmitted can be less than the number desired.
 *
 *  @param      pBuffer
 *                  Buffer containing the data to be sent.
 *  @param      pBufLen
 *                  Number of bytes to be transmitted.
 *
 *  @return     Returns the number of bytes actually sent, or -1 in
 *              case of an error.  Call GetLastError() to get the
 *              actual error code.
 *------------------------------------------------------------------*/
int VSocket::Send(const char *pBuffer, int pBufLen) {
	int vRetval = 0;

	BEG_FUNC("Send")("%p, %d", pBuffer, pBufLen);

	vRetval = send(mHandle, pBuffer, pBufLen, MSG_NOSIGNAL);

	if (vRetval > 0) {
		VTRACE("%d bytes transmitted\n", vRetval);
	} else if (vRetval < 0) {
		SETERRNO();
		mError = errno;
	}

	return END_FUNC(vRetval);
}
Пример #16
0
int my_getpeername(int sock, struct sockaddr *addr, int *addrlen) {
  static char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  int rslt;

  rslt = si_getpeername(sock, addr, addrlen);

  /* Just pass an error back up the line */
  if (rslt) return rslt;

  /* If the call succeeded, make sure we don't have a zeroed port/addr */
  if (addr->sa_family == AF_INET &&
      !memcmp((char *)addr + sizeof(u_short), nowhere,
              sizeof(u_short) + sizeof(struct in_addr))) {
    rslt = -1;
    SETERRNO(ENOTCONN,SS$_CLEARED);
  }
  return rslt;
}
Пример #17
0
IV
PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg,
		    PerlIO_funcs * tab)
{
    IV code;
    PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar);
    /* If called (normally) via open() then arg is ref to scalar we are
     * using, otherwise arg (from binmode presumably) is either NULL
     * or the _name_ of the scalar
     */
    if (arg) {
	if (SvROK(arg)) {
	    if (SvREADONLY(SvRV(arg)) && mode && *mode != 'r') {
		if (ckWARN(WARN_LAYER))
		    Perl_warner(aTHX_ packWARN(WARN_LAYER), "%s", PL_no_modify);
		SETERRNO(EINVAL, SS_IVCHAN);
		return -1;
	    }
	    s->var = SvREFCNT_inc(SvRV(arg));
	    SvGETMAGIC(s->var);
	    if (!SvPOK(s->var) && SvOK(s->var))
		(void)SvPV_nomg_const_nolen(s->var);
	}
	else {
	    s->var =
		SvREFCNT_inc(perl_get_sv
			     (SvPV_nolen(arg), GV_ADD | GV_ADDMULTI));
	}
    }
    else {
	s->var = newSVpvn("", 0);
    }
    SvUPGRADE(s->var, SVt_PV);
    code = PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
    if (!SvOK(s->var) || (PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE)
	SvCUR_set(s->var, 0);
    if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND)
	s->posn = SvCUR(s->var);
    else
	s->posn = 0;
    return code;
}
Пример #18
0
/**
 *  @brief      Accept a pending connection from the incoming queue.
 *
 *  @param      pNewSocket
 *                  Pointer to hold the newly accepted socket.
 *  @param      pSockAddr
 *                  Pointer to hold the address info for the remote
 *                  socket.
 *  @param      pSockAddrLen
 *                  Size of the address pointer.
 *------------------------------------------------------------------*/
bool VSocket::Accept(VSocket* pNewSocket, sockaddr* pSockAddr/*=NULL*/,
		socklen_t* pSockAddrLen/*=NULL*/) {
	SOCKET  vTempHandle = -1; /* temp Socket ID */
	SOCKET  vNewHandle = -1; /* new Socket ID  */
	int     vPeerSize;
	bool    vRetval = false;
	bool    vOk = true;

	BEG_FUNC("Accept")("%p, %p, %p", pNewSocket, pSockAddr, pSockAddrLen);

	if (mStatus != SS_LISTENING) { /* Socket not in listening mode! */
		VTRACE("Socket not in listening mode. Cannot accept "
				"incoming connection\n");
		mError = EINVAL;
		return END_FUNC(false);
	}

	/* We are in a proper state to accept connections.  Try it! */
	vPeerSize = sizeof(mEndPoint);
	vTempHandle = mHandle;

	/* Attempt to accept the connection */
	vNewHandle = accept(vTempHandle, (struct sockaddr*)&mEndPoint, (socklen_t*)&vPeerSize);
	if (vNewHandle >= 0) {
		/* Accepted an incoming connection */
		VTRACE("Connection accepted\n");
		pNewSocket->Attach(vNewHandle);
		if (pSockAddr != NULL)
			memcpy(pSockAddr, &mEndPoint, vPeerSize);

		if (pSockAddrLen != NULL)
			*pSockAddrLen = vPeerSize;
		vRetval = true;
	} else {
		SETERRNO();
		mError = errno;
		VTRACE("accept failed with error code %d\n", errno);
	}

	return END_FUNC(vRetval);
}
Пример #19
0
PDBWIN_BUFFER_t OutputMonitor::__GetDbWinBuffer()
{
    PDBWIN_BUFFER_t pRetBuffer=NULL;
    int ret = 0;

    EnterCriticalSection(&(this->m_CS));
    if(this->m_pFreeBuffers && this->m_pFreeBuffers->size() > 0) {
        pRetBuffer = this->m_pFreeBuffers->at(0);
        this->m_pFreeBuffers->erase(this->m_pFreeBuffers->begin());
    }
    LeaveCriticalSection(&(this->m_CS));

    if(pRetBuffer == NULL) {
        pRetBuffer = (PDBWIN_BUFFER_t)malloc(sizeof(*pRetBuffer));
        if(pRetBuffer == NULL) {
            ret = GETERRNO();
        }
    }

    SETERRNO(ret);
    return pRetBuffer;
}
Пример #20
0
/**
 *  @brief      DNS lookup function.  Converts host to IP address.
 *
 *  @param      pHost
 *                  Host name to be converted.
 *  @param      pIPaddr
 *                  Buffer to hold the converted addr.
 *  @param      pSize
 *                  Size of pcIPaddr.
 *------------------------------------------------------------------*/
bool VSocket::GetIPbyName(const char *pHost, char *pIPaddr, int pSize) {
	struct  hostent *vHostInfo;
	bool    vRetval = false;

	BEG_FUNC("GetIPbyName")("%p, %p, %d", pHost, pIPaddr, pSize);

	*pIPaddr = 0;
	vHostInfo = gethostbyname(pHost);

	if (vHostInfo) {
		struct in_addr *vAddr;
		vAddr = (struct in_addr*)vHostInfo->h_addr_list[0];
		strncpy(pIPaddr, inet_ntoa(*vAddr), pSize-1);
		VTRACE("Address (%s) resolved to (%s)\n", pHost, pIPaddr);
		vRetval = true;
	} else {
		SETERRNO();
		mError = errno;
	}

	return END_FUNC(vRetval);
}
Пример #21
0
/**
 *  @brief      Retrieve data pending on this socket.
 *
 *  @remarks    Should be called by OnReceive(), when data is known
 *              to be available.
 *
 *  @param      pBuffer
 *                  Buffer to hold the retrieved data.
 *  @param      pBufLen
 *                  Maximum length of pcBuffer.
 *  @param      pFlags
 *                  Options to be passed to recv().
 *------------------------------------------------------------------*/
int VSocket::Receive(char *pBuffer, int pBufLen, int pFlags) {
	bool    vContinue = true;
	int     vRetval = -1;

	BEG_FUNC("Receive")("%p, %d, %d", pBuffer, pBufLen, pFlags);

	/*
	 * Are we connected?
	 */
	if (mStatus != SS_CONNECTED) {
		VTRACE("Error-not connected\n");
		mError = ENOTCONN;
		vContinue = false;
	}

	if (pBuffer == NULL) {
		VTRACE("Error-null buffer passed\n");
		mError = EINVAL;
		vContinue = false;
	} else {
		if (pBufLen <= 0) {
			VTRACE("Error-invalid buffer length specified\n");
			mError = EINVAL;
		} else {
			vRetval = recv(mHandle, pBuffer, pBufLen, pFlags);
			if (vRetval == -1) {
				SETERRNO();
				mError = errno;
			} else if (vRetval > 0) {
				pBuffer[vRetval] = 0;
				VTRACE("Received-%s\n", pBuffer);
			}
		}
	}

	return END_FUNC(vRetval);
}
Пример #22
0
int OutputMonitor::__CreateBuffers()
{
    int ret=0;

    assert(this->m_pFreeBuffers == NULL);
    assert(this->m_pAvailBuffers == NULL);

    this->m_pAvailBuffers = new std::vector<PDBWIN_BUFFER_t>();
    if(this->m_pAvailBuffers == NULL) {
        ret = GETERRNO();
        goto fail;
    }
    this->m_pFreeBuffers = new std::vector<PDBWIN_BUFFER_t>();
    if(this->m_pFreeBuffers == NULL) {
        ret = GETERRNO();
        goto fail;
    }

    return 0;
fail:
    this->__ClearBuffers();
    SETERRNO(ret);
    return -ret;
}
Пример #23
0
double
__erfc( double arg )
{
double argsq;
double z;
double zsq;
double s, f, f1;
double n, d;
double result;
#ifdef _CALL_MATHERR
struct exception	exstruct;
#endif

	if( arg != arg )
	{
		/* arg is a NaN */

#ifdef _CALL_MATHERR

		exstruct.type = DOMAIN;
		exstruct.name = "erfc";
		exstruct.arg1 = arg;
		exstruct.retval = Qnan.d;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "domain error in erfc\n");
			SETERRNO(EDOM);
		}

		return ( exstruct.retval );
#else
		NAN_SETERRNO(EDOM);

		return ( Qnan.d );
#endif
	}

	if ( arg < Llimit2.d )
		return ( 2.0 );

	if ( arg <= -2.0 )
		return ( 2.0 - __erfc(-arg) );

	if ( arg < 0.25 )
		return( 1.0 - __erf(arg) );

	result = 0.0; /* default */

	if ( arg < 0.75 )
	{
		argsq = arg*arg;

		n = (((((p1[6].d*argsq + p1[5].d)*argsq + p1[4].d)*argsq +
				p1[3].d)*argsq + p1[2].d)*argsq + p1[1].d)*
				argsq + p1[0].d;

		d = ((((q1[5].d*argsq + q1[4].d)*argsq + q1[3].d)*argsq +
				q1[2].d)*argsq + q1[1].d)*argsq + q1[0].d;

		return ( 0.5 + ((0.5 - arg) - arg*n/d) );
	}
	else if ( arg < 1.25 )
	{
		z = arg - 1.0;

		n = ((((((p2[8].d*z + p2[7].d)*z + p2[6].d)*z + p2[5].d)*z +
			p2[4].d)*z + p2[3].d)*z + p2[2].d)*z;
		d = ((((((q2[7].d*z + q2[6].d)*z + q2[5].d)*z + q2[4].d)*z +
			q2[3].d)*z + q2[2].d)*z + q2[1].d)*z + q2[0].d;

		return ( p2[0].d - n/d );
	}
	else if ( arg < 1.75 )
	{
		z = arg - 1.5;

		n = (((((p3[7].d*z + p3[6].d)*z +
			p3[5].d)*z + p3[4].d)*z + p3[3].d)*z + p3[2].d)*z;
		d = (((((q3[6].d*z + q3[5].d)*z +  q3[4].d)*z +
			q3[3].d)*z + q3[2].d)*z + q3[1].d)*z + q3[0].d;

		return ( p3[0].d - n/d );
	}
	else if ( arg < 2.0 )
	{
		z = arg - 1.875;

		n = ((((p4[6].d*z + p4[5].d)*z +
			p4[4].d)*z + p4[3].d)*z + p4[2].d)*z;
		d = ((((q4[5].d*z + q4[4].d)*z + q4[3].d)*z +
			q4[2].d)*z + q4[1].d)*z + q4[0].d;

		return ( p4[0].d - n/d );
	}
	else if ( arg <= Ulimit2.d )
	{
		zsq = 1.0/(arg*arg);

		n = (((((((p5[7].d*zsq + p5[6].d)*zsq + p5[5].d)*zsq +
			p5[4].d)*zsq + p5[3].d)*zsq + p5[2].d)*zsq + p5[1].d)*zsq +
			p5[0].d)*zsq;

		d = (((((((q5[8].d*zsq + q5[7].d)*zsq + q5[6].d)*zsq + q5[5].d)*zsq +
			q5[4].d)*zsq + q5[3].d)*zsq + q5[2].d)*zsq + q5[1].d)*zsq +
			q5[0].d;

		s = (float)arg;

		/* Now the result is exp(-arg*arg)*(1.0 + n/d)/(arg*sqrt(pi)) */

		if ( arg <= 26.0 )
		{
			/* To avoid loss of precision in computing exp(-arg*arg),
			 * rewrite -arg*arg as -s*s + s*(s-arg) + arg*(s-arg)
			 * Note that -s*s is exact.
			 */

			/* Compute the second exp in the expression locally,
			 * since the argument is small.
			 */

			f1 = __exp(-s*s);
			f = f1 + f1*poly(s*(s-arg) + arg*(s-arg));

			return ( Rsqrtpi.d*(f + f*n/d)/arg );
		}
		else
		{
			/* Beyond 26.0, we have to worry about underflow in
			 * computing exp(-arg*arg); instead we'll compute 
			 * exp(-arg*arg/2.0) and multiply by it twice.
			 * The result here may underflow, depending on 
			 * whether the processor supports denormals or not.
			 */


			s = (float)arg;

			f1 = __exp(-0.5*s*s);
			f = f1 + f1*poly(0.5*s*(s-arg) + 0.5*arg*(s-arg));

			result = Rsqrtpi.d*(f + f*n/d)/arg*f;
		}
	}

	if ( result == 0.0 )

#ifdef _CALL_MATHERR

	{
		exstruct.type = UNDERFLOW;
		exstruct.name = "erfc";
		exstruct.arg1 = arg;
		exstruct.retval = 0.0;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "underflow error in erfc\n");
			SETERRNO(ERANGE);
		}

		return ( exstruct.retval );
	}
#else
	{
		SETERRNO(ERANGE);

		return ( 0.0 );
	}
#endif

	return ( result );
}
Пример #24
0
double
__erf( double arg )
{
double __erfc(double);
double sign;
double argsq;
double d, n, z;
#ifdef _CALL_MATHERR
struct exception	exstruct;
#endif

	if( arg != arg )
	{
		/* arg is a NaN */

#ifdef _CALL_MATHERR

		exstruct.type = DOMAIN;
		exstruct.name = "erf";
		exstruct.arg1 = arg;
		exstruct.retval = Qnan.d;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "domain error in erf\n");
			SETERRNO(EDOM);
		}

		return ( exstruct.retval );
#else
		NAN_SETERRNO(EDOM);

		return ( Qnan.d );
#endif
	}

	sign = 1.0;

	if( arg < 0. )
	{
		arg = -arg;
		sign = -1.0;
	}

	if ( arg < 0.75 )
	{
		argsq = arg*arg;


		n = (((((p1[6].d*argsq + p1[5].d)*argsq + p1[4].d)*argsq +
				p1[3].d)*argsq + p1[2].d)*argsq + p1[1].d)*
				argsq + p1[0].d;

		d = ((((q1[5].d*argsq + q1[4].d)*argsq + q1[3].d)*argsq +
				q1[2].d)*argsq + q1[1].d)*argsq + q1[0].d;

		return ( sign*(arg + arg*n/d) );

	}
	else if ( arg < 1.25 )
	{
		z = arg - 1.0;

		n = ((((((p2[8].d*z + p2[7].d)*z + p2[6].d)*z + p2[5].d)*z +
			p2[4].d)*z + p2[3].d)*z + p2[2].d)*z;
		d = ((((((q2[7].d*z + q2[6].d)*z + q2[5].d)*z + q2[4].d)*z +
			q2[3].d)*z + q2[2].d)*z + q2[1].d)*z + q2[0].d;

		return ( sign*(p2[1].d + n/d) );
	}
	else if ( arg < 1.75 )
	{
		z = arg - 1.5;

		n = (((((p3[7].d*z + p3[6].d)*z +
			p3[5].d)*z + p3[4].d)*z + p3[3].d)*z + p3[2].d)*z;
		d = (((((q3[6].d*z + q3[5].d)*z + q3[4].d)*z +
			q3[3].d)*z + q3[2].d)*z + q3[1].d)*z + q3[0].d;

		return ( sign*(p3[1].d + n/d) );
	}
	else if ( arg < 2.0 )
	{
		z = arg - 1.875;

		n = ((((p4[6].d*z + p4[5].d)*z +
			p4[4].d)*z + p4[3].d)*z + p4[2].d)*z;
		d = ((((q4[5].d*z + q4[4].d)*z + q4[3].d)*z +
			q4[2].d)*z + q4[1].d)*z + q4[0].d;

		return ( sign*(p4[1].d + n/d) );
	}

	if ( fabs(arg) <= Ulimit1.d )
		return( sign*(1.0 - __erfc(arg)) );
	else
		return ( sign );
}
Пример #25
0
float
__log1pf( float x )
{
int	xpt;
float	u, v;
double	u1;
float	q;
float	result;
int	m, n;
float	y, f, F;
float	l_lead, l_trail;
int	j, k;
float	twopnegm;
float	md;
#ifdef _CALL_MATHERR
struct exception	exstruct;
#endif

	if ( x != x )
	{
		/* x is a NaN; return a quiet NaN */

#ifdef _CALL_MATHERR

                exstruct.type = DOMAIN;
                exstruct.name = "log1pf";
                exstruct.arg1 = x;
                exstruct.retval = Qnan.f;

                if ( matherr( &exstruct ) == 0 )
                {
                        fprintf(stderr, "domain error in log1pf\n");
                        SETERRNO(EDOM);
                }

                return ( exstruct.retval );
#else
		NAN_SETERRNO(EDOM);
		
		return ( Qnan.f );
#endif
	}

	if ( (T1.f < x) && (x < T2.f) )
	{
		/*  exp(-1/16) < 1 + x < exp(1/16)  */

		FLT2INT(x, xpt);	/* copy arg to an integer	*/
		xpt >>= MANTWIDTH;	/* shift off mantissa	*/
		xpt &= 0xff;

		if ( xpt >= 0x67 )
		{
			/* |x| >= 2^(-24) */

			u1 = x/(2.0 + x);
			u1 = u1 + u1;
			u = u1;
			v = u1*u1;

			q = (P[2].f*v + P[1].f)*(v*u);

			result = u1 + q;

			return ( result );
		}

		return ( x );
	}
Пример #26
0
double
__log1p( double x )
{
#ifdef _32BIT_MACHINE

int	xpt;
int	k, m, n;

#else

long long xpt;
long long k, m, n;

#endif
int	j;
double	g, u, v, x1, x2;
double	u1, u2;
double	q;
double	twopnegm;
double	result;
double	y, f, F;
double	l_lead, l_trail;
#ifdef _CALL_MATHERR
struct exception	exstruct;
#endif

	if ( x != x )
	{
		/* x is a NaN; return a quiet NaN */

#ifdef _CALL_MATHERR

		exstruct.type = DOMAIN;
		exstruct.name = "log1p";
		exstruct.arg1 = x;
		exstruct.retval = Qnan.d;

		if ( matherr( &exstruct ) == 0 )
		{
			fprintf(stderr, "domain error in log1p\n");
			SETERRNO(EDOM);
		}

		return ( exstruct.retval );
#else
		NAN_SETERRNO(EDOM);

		return ( Qnan.d );
#endif
	}

	if ( (T1.d < x) && (x < T2.d) )
	{
#ifdef _32BIT_MACHINE

		DBLHI2INT(x, xpt);	/* copy MSW of arg to an int	*/
#else
		DBL2LL(x, xpt);		/* copy arg to an int	*/
#endif
		xpt >>= DMANTWIDTH;	/* shift off mantissa	*/
		xpt &= 0x7ff;

		if ( xpt >= 0x3ca )
		{
			/* |x| >= 2^(-53) */

			g = 1.0/(2.0 + x);

			u = x*g;
			u = u + u;
			v = u*u;

			q = (((Q[4].d*v + Q[3].d)*v + Q[2].d)*v +
				Q[1].d)*v*u;

			u1 = (float)u;	/* round u to 24 bits */
			x1 = (float)x;	/* round x to 24 bits */

			x2 = x - x1;
			u2 = x - u1;
			u2 = u2 + u2;
			u2 = ((u2 - u1*x1) - u1*x2)*g;

			result = u1 + (u2 + q);

			return ( result );
		}

		return ( x );
	}
Пример #27
0
/**
 *  @brief      Polls the socket for read/writability.
 *
 *  @param      pFlags
 *                  FD_READ, FD_WRITE, or both.
 *  @param      pTimeout
 *                  Length of time to poll.
 *------------------------------------------------------------------*/
VRESULT VSocket::Select(long *pFlags, VUSHORT pTimeout) {
	SOCKET          vTempSock = INVALID_SOCKET;
	struct timeval  vSeltime;
	fd_set          vReadfds, vWritefds, vExcpfds;
	int             vRetval = -1;
	long            vTempFlags;

	BEG_FUNC("Select")("%p, %ld, %d", pFlags, *pFlags, pTimeout);
	vTempSock = mHandle;

	if (*pFlags == 0L) {
		VTRACE("Nothing to do.  0 passed for flags\n");
		return END_FUNC(VERR_SUCCESS);
	}

	vSeltime.tv_sec = pTimeout;
	vSeltime.tv_usec = 0;
	vTempFlags = *pFlags;

	while (1) {
		FD_ZERO(&vReadfds);
		FD_ZERO(&vWritefds);
		FD_ZERO(&vExcpfds);

		VTRACE(" * Flags passed *\n");
		if (vTempFlags & FD_READ) {
			VTRACE("READ\n");
			FD_SET(vTempSock, &vReadfds);
		}
		if (vTempFlags & FD_WRITE) {
			VTRACE("WRITE\n");
			FD_SET(vTempSock, &vWritefds);
		}
		FD_SET(vTempSock, &vExcpfds);

		VTRACE("Socket ID: %d\n", vTempSock);

		*pFlags = 0L;

		vRetval = select(vTempSock+1, &vReadfds, &vWritefds, &vExcpfds, &vSeltime);
		SETERRNO();
		mError = errno;

		if (vRetval < 0) {
			VERROR("Error calling select().\nError => [%d:%s]\n", errno, strerror(errno));
			return END_FUNC(VERR_NET);
		} else if (vRetval == 0) {
			VTRACE("select() returned 0\n");
			return END_FUNC(VERR_SUCCESS);
		} else {
			VTRACE("select returned %d\n", vRetval);
			if (FD_ISSET(vTempSock, &vReadfds)) {
				VTRACE("Socket readable\n");
				*pFlags |= FD_READ;
			}
			if (FD_ISSET(vTempSock, &vWritefds)) {
				VTRACE("Socket writable\n");
				*pFlags |= FD_WRITE;
			}

			if (FD_ISSET(vTempSock, &vExcpfds)) {
				VTRACE("Socket has exception set\n");
				VTRACE("errno => %d:%s\n", errno, strerror(errno));
				*pFlags |= FD_READ; // so the client picks up on the error
			}
			break;
		}
	}

	return END_FUNC(VERR_SUCCESS);
}
Пример #28
0
int OutputMonitor::__CreateMutexEvent()
{
    int ret;

    assert(this->m_hNotifyEvt == NULL);
    assert(this->m_hDBWinMutex == NULL);
    assert(this->m_hDBWinBufferReady == NULL);
    assert(this->m_hDBWinDataReady == NULL);

    this->m_hNotifyEvt = GetEvent(NULL,1);
    if(this->m_hNotifyEvt == NULL) {
        ret = GETERRNO();
        goto fail;
    }

    /*now first to make sure that the*/
    if (this->m_GlobalWin32) {
        this->m_hDBWinMutex = GetMutex("Global\\DBWinMutex",0);
    } else {
        this->m_hDBWinMutex = GetMutex("DBWinMutex", 0);
    }
    if(this->m_hDBWinMutex == NULL) {
        if (this->m_GlobalWin32) {
            this->m_hDBWinMutex = GetMutex("Global\\DBWinMutex",1);
        } else {
            this->m_hDBWinMutex = GetMutex("DBWinMutex", 1);
        }

        if(this->m_hDBWinMutex == NULL) {
            ret = GETERRNO();
            goto fail;
        }
    }

    if (this->m_GlobalWin32) {
        this->m_hDBWinBufferReady = GetEvent("Global\\DBWIN_BUFFER_READY", 0);
    } else {
        this->m_hDBWinBufferReady = GetEvent("DBWIN_BUFFER_READY", 0);
    }
    if(this->m_hDBWinBufferReady == NULL) {
        if (this->m_GlobalWin32) {
            this->m_hDBWinBufferReady = GetEvent("Global\\DBWIN_BUFFER_READY", 1);
        } else {
            this->m_hDBWinBufferReady = GetEvent("DBWIN_BUFFER_READY", 1);
        }
        if(this->m_hDBWinBufferReady == NULL) {
            ret = GETERRNO();
            goto fail;
        }
    }


    if (this->m_GlobalWin32) {
        this->m_hDBWinDataReady = GetEvent("Global\\DBWIN_DATA_READY", 0);
    } else {
        this->m_hDBWinDataReady = GetEvent("DBWIN_DATA_READY", 0);
    }
    if(this->m_hDBWinDataReady == NULL) {
        if (this->m_GlobalWin32) {
            this->m_hDBWinDataReady = GetEvent("Global\\DBWIN_DATA_READY", 1);
        } else {
            this->m_hDBWinDataReady = GetEvent("DBWIN_DATA_READY", 1);
        }
        if(this->m_hDBWinDataReady == NULL) {
            ret = GETERRNO();
            goto fail;
        }
    }

    SETERRNO(0);
    return 0;
fail:
    this->__CloseMutexEvent();
    SETERRNO(ret);
    return -ret;
}
Пример #29
0
/**
 *  @brief      Establish a connection with a remote machine.
 *
 *  @param      pAddress
 *                  Address to connect to.
 *  @param      pPort
 *                  Port number to connect to.
 *------------------------------------------------------------------*/
bool VSocket::Connect(const char *pAddress, VUSHORT pPort) {
	int     vResult = 0;
	bool    vRetval = true;
	char    vDestAddr[IP_ADDR_LEN];
	VULONG  vAddrIP;

	BEG_FUNC("Connect")("%p[%s], %d, %d", pAddress, pAddress, pPort);

	/*
	 * Already connected?
	 */
	if (mStatus == SS_CONNECTED) {
		VERROR("Socket already connected %s:%d\n", mEndPoint.GetAddr(),
				mEndPoint.GetPort());
		mError = EISCONN;
		return END_FUNC(VERR_ALREADY_IN_USE);
	}

	/*
	 * Socket initialized?
	 */
	if (mStatus != SS_ALLOCATED && mStatus != SS_BOUND) {
		VERROR("Error-Socket not initialized\n");
		mError = ENOTSOCK;
		return END_FUNC(VERR_INVALID_STATUS);
	}

	/*
	 * Resolve the destination: Name or Address?
	 */
	if (!GetIPbyName(pAddress, vDestAddr, sizeof(vDestAddr)))
		strncpy(vDestAddr, pAddress, IP_ADDR_LEN-1); // Copy in the address passed and try it

	/*
	 * Convert the address to network byte order.
	 */
	vAddrIP = inet_addr(vDestAddr);
	if (vAddrIP == INADDR_NONE) { // Invalid address format
		VERROR("Unable to resolve address: %s\n", vDestAddr);
		mError = EINVAL;
		return END_FUNC(VERR_RESOLVE_ERROR);
	} else {
		mEndPoint.SetPort(pPort);
		mEndPoint.SetAddrIP(vAddrIP);
		VTRACE("Address %s resolved to %s\n", vDestAddr, mEndPoint.GetAddr());

		mStatus = SS_CONNECTING;

		/*
		 * Try and establish the connection.
		 */
		vResult = connect(mHandle, (struct sockaddr*)&mEndPoint,
				sizeof(sockaddr_in));
		if (vResult != 0) {
			SETERRNO();
			mError = errno;
			VERROR("connect returned error-%d:%s\n", errno,
					strerror(errno));
			return END_FUNC(VERR_CONNECT);
		} else {
			mStatus = SS_CONNECTED; // Connection established.  EUREKA!
		}

		if (vRetval != -1) {
			memset(vDestAddr, 0, IP_ADDR_LEN);
			GetSockName(vDestAddr, IP_ADDR_LEN, &pPort);
			mLocal.sin_family = AF_INET;
			mLocal.SetPort(pPort);
			mLocal.SetAddr(vDestAddr);
		}
	}

	return END_FUNC(vRetval);
}
Пример #30
0
/**
 *  @brief      Binds this socket object to a specific port and
 *              (optional) address.
 *
 *  @param      pPort
 *                  Port number to bind to
 *  @param      pAddress
 *                  (Optional) Address to bind to
 *------------------------------------------------------------------*/
bool VSocket::Bind(VUSHORT pPort, const char *pAddress/*=NULL*/) {
	char    vDestAddr[IP_ADDR_LEN];
	bool    vRetval = false;
	int     vReturnCode = 0;
	VULONG  vAddrIP;

	BEG_FUNC("Bind")("%d, %p", pPort, pAddress);

	/*
	 * Socket initialized?
	 */
	if (mStatus != SS_ALLOCATED) {
		VTRACE("Error-Socket not initialized\n");
		mError = ENOTSOCK;
		return END_FUNC(false);
	}

	/*
	 * Are we already bound?
	 */
	if (mStatus == SS_BOUND) {
		VTRACE("Error-Socket already bound to %s:%d\n",
				mLocal.GetAddr(), mLocal.GetPort());
		mError = EINVAL;
		return END_FUNC(false);
	}

	if (pAddress == NULL) {
		mPort = pPort;
		mLocal.sin_family = AF_INET;
		mLocal.SetPort(pPort);
		mLocal.SetAddrIP(INADDR_ANY);
	} else {
		// Resolve the destination: Name or Address?
		if (!GetIPbyName(pAddress, vDestAddr, sizeof(vDestAddr)))
			strncpy(vDestAddr, pAddress, IP_ADDR_LEN); // Copy in the address passed

		// Convert the address to network byte order
		vAddrIP = inet_addr(vDestAddr);
		if (vAddrIP != INADDR_NONE) { // Valid address format
			mPort = pPort;
			mLocal.sin_family = AF_INET;
			mLocal.SetPort(pPort);
			mLocal.SetAddrIP(vAddrIP);
			VTRACE("Address resolved to %s\n", vDestAddr);
		} else {
			VTRACE("Unable to resolve address\n");
			mError = EINVAL;
			return END_FUNC(false);
		}
	}

	/*
	 * Try to bind to the specified port/address.
	 */
	vReturnCode = bind(mHandle, (struct sockaddr*)&mLocal, sizeof(sockaddr_in));
	if (vReturnCode == 0) {
		// Socket successfully bound.
		mStatus = SS_BOUND;
		VTRACE("Bound to port %d\n", pPort);
		return END_FUNC(true);
	} else {
		//--------------------------------------//
		// Determine the cause of the failure.  //
		// Normally a failed call to bind       //
		// indicates the local port is in use.  //
		//--------------------------------------//
		SETERRNO();
		mError = errno;
		VTRACE("bind failed.  Errno code %d\n", mError);
		return END_FUNC(false);
	}
}