Exemplo n.º 1
0
CT_INT_TYPE CConn_Streambuf::underflow(void)
{
    _ASSERT(gptr() >= egptr());

    if (!m_Conn)
        return CT_EOF;

    // flush output buffer, if tied up to it
    if (m_Tie  &&  x_sync() != 0)
        return CT_EOF;

#ifdef NCBI_COMPILER_MIPSPRO
    if (m_MIPSPRO_ReadsomeGptrSetLevel  &&  m_MIPSPRO_ReadsomeGptr != gptr())
        return CT_EOF;
    m_MIPSPRO_ReadsomeGptr = (CT_CHAR_TYPE*)(-1L);
#endif /*NCBI_COMPILER_MIPSPRO*/

    // read from connection
    size_t n_read;
    m_Status = CONN_Read(m_Conn, m_ReadBuf, m_BufSize,
                         &n_read, eIO_ReadPlain);
    _ASSERT(n_read <= m_BufSize);
    if (!n_read) {
        _ASSERT(m_Status != eIO_Success);
        if (m_Status != eIO_Closed)
            ERR_POST_X(8, x_Message("underflow():  CONN_Read() failed"));
        return CT_EOF;
    }

    // update input buffer with the data just read
    x_GPos += (CT_OFF_TYPE) n_read;
    setg(m_ReadBuf, m_ReadBuf, m_ReadBuf + n_read);

    return CT_TO_INT_TYPE(*m_ReadBuf);
}
Exemplo n.º 2
0
void sync_speed_test(int connection_key)
{
        x_endpoint_handle_t endpoint = x_get_endpoint(connection_key);
        int i, j;
        for (i = 0; i < 10000; i++) {
          for (j = 0; j < 1000; j++) {
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
            x_sync(endpoint);
          }
          x_task_heartbeat();
        }
}
Exemplo n.º 3
0
void sync_test (int connection_key)
{
        x_endpoint_handle_t endpoint = x_get_endpoint(connection_key);
        if (connection_key == X_TO_LEFT) {
          x_sleep(6);
          x_set_task_status ("First sync to left %x",endpoint);
          x_sync(endpoint);
          x_set_task_status ("First sync done");
          x_sleep(3);
          x_set_task_status ("Second sync to left");
          x_sync(endpoint);
          x_set_task_status ("Second sync done");
        }
        else if (connection_key == X_FROM_RIGHT) {
          x_sleep(3);
          x_set_task_status ("First sync from right %x",endpoint);
          x_sync(endpoint);
          x_set_task_status ("First sync done");
          x_sleep(6);
          x_set_task_status ("Second from right");
          x_sync(endpoint);
          x_set_task_status ("Second sync done");
        }
}
Exemplo n.º 4
0
/* Output "page" */
static int
x_output_page(gx_device * dev, int num_copies, int flush)
{
    gx_device_X *xdev = (gx_device_X *) dev;

    x_sync(dev);

    /* Send ghostview a "page" client event */
    /* Wait for a "next" client event */
    if (xdev->ghostview) {
        XEvent event;

        gdev_x_send_event(xdev, xdev->PAGE);
        XNextEvent(xdev->dpy, &event);
        while (event.type != ClientMessage ||
               event.xclient.message_type != xdev->NEXT) {
            XNextEvent(xdev->dpy, &event);
        }
    }
    return gx_finish_output_page(dev, num_copies, flush);
}
Exemplo n.º 5
0
CRWStreambuf::~CRWStreambuf()
{
    try {
        // Flush only if data pending and no error
        if (!x_Err  ||  x_ErrPos != x_GetPPos())
            x_sync();
        setg(0, 0, 0);
        setp(0, 0);

        IReaderWriter* rw = dynamic_cast<IReaderWriter*> (m_Reader);
        if (rw  &&  rw == dynamic_cast<IReaderWriter*> (m_Writer)) {
            if ((m_Flags & fOwnAll) == fOwnAll)
                delete rw;
        } else {
            if (m_Flags & fOwnWriter)
                delete m_Writer;
            if (m_Flags & fOwnReader)
                delete m_Reader;
        }

        delete[] m_pBuf;
    } NCBI_CATCH_ALL_X(2, "Exception in ~CRWStreambuf() [IGNORED]");
}
Exemplo n.º 6
0
streamsize CConn_Streambuf::showmanyc(void)
{
    static const STimeout kZeroTmo = {0, 0};

    _ASSERT(gptr() >= egptr());

    if (!m_Conn)
        return -1L;

    // flush output buffer, if tied up to it
    if (m_Tie)
        x_sync();

    const STimeout* tmo;
    const STimeout* timeout = CONN_GetTimeout(m_Conn, eIO_Read);
    if (timeout == kDefaultTimeout) {
        // HACK * HACK * HACK
        tmo = ((SMetaConnector*) m_Conn)->default_timeout;
    } else
        tmo = timeout;

    size_t x_read;
    bool backup = false;
    if (m_BufSize > 1) {
        if (eback() < gptr()) {
            x_Buf = gptr()[-1];
            backup = true;
        }
        if (!tmo)
            _VERIFY(CONN_SetTimeout(m_Conn, eIO_Read, &kZeroTmo)==eIO_Success);
        m_Status = CONN_Read(m_Conn, m_ReadBuf + 1, m_BufSize - 1,
                             &x_read, eIO_ReadPlain);
        if (!tmo)
            _VERIFY(CONN_SetTimeout(m_Conn, eIO_Read, timeout)  ==eIO_Success);
        _ASSERT(x_read > 0  ||  m_Status != eIO_Success);
    } else {
        m_Status = CONN_Wait(m_Conn, eIO_Read, tmo ? tmo : &kZeroTmo);
        x_read = 0;
    }

    if (!x_read) {
        switch (m_Status) {
        case eIO_Success:
            _ASSERT(m_BufSize <= 1);
            return  1L;  // can read at least 1 byte
        case eIO_Timeout:
            if (!tmo  ||  !(tmo->sec | tmo->usec))
                break;
            /*FALLTHRU*/
        case eIO_Closed:
            return -1L;  // EOF
        default:
            break;
        }
        return       0;  // no data available immediately
    }

    m_ReadBuf[0] = x_Buf;
    _ASSERT(m_BufSize > 1);
    setg(m_ReadBuf + !backup, m_ReadBuf + 1, m_ReadBuf + 1 + x_read);
    x_GPos += x_read;
    return x_read;
}
Exemplo n.º 7
0
streamsize CConn_Streambuf::xsgetn(CT_CHAR_TYPE* buf, streamsize m)
{
    if (!m_Conn)
        return 0;

    // flush output buffer, if tied up to it
    if (m_Tie  &&  x_sync() != 0)
        return 0;

    if (m < 0)
        return 0;

    _ASSERT((Uint8) m < numeric_limits<size_t>::max());
    size_t n = (size_t) m;
    size_t n_read;

    if (n) {
        // first, read from the memory buffer
        n_read = (size_t)(egptr() - gptr());
        if (n_read > n)
            n_read = n;
        memcpy(buf, gptr(), n_read);
        gbump(int(n_read));
        n   -= n_read;
        if (!n)
            return (streamsize) n_read;
        buf += n_read;
    } else
        n_read = 0;

    do {
        // next, read from the connection
        size_t     x_toread = n  &&  n < m_BufSize ? m_BufSize : n;
        CT_CHAR_TYPE* x_buf =        n < m_BufSize ? m_ReadBuf : buf;
        size_t       x_read;

        m_Status = CONN_Read(m_Conn, x_buf, x_toread,
                             &x_read, eIO_ReadPlain);
        _ASSERT(x_read <= x_toread);
        if (!x_read) {
            _ASSERT(!x_toread  ||  m_Status != eIO_Success);
            if (m_Status != eIO_Success  &&  m_Status != eIO_Closed)
                ERR_POST_X(10, x_Message("xsgetn():  CONN_Read() failed"));
            break;
        }
        x_GPos += (CT_OFF_TYPE) x_read;
        // satisfy "usual backup condition", see standard: 27.5.2.4.3.13
        if (x_buf == m_ReadBuf) {
            size_t xx_read = x_read;
            if (x_read > n)
                x_read = n;
            memcpy(buf, m_ReadBuf, x_read);
            setg(m_ReadBuf, m_ReadBuf + x_read, m_ReadBuf + xx_read);
        } else {
            _ASSERT(x_read <= n);
            size_t xx_read = x_read > m_BufSize ? m_BufSize : x_read;
            memcpy(m_ReadBuf, buf + x_read - xx_read, xx_read);
            setg(m_ReadBuf, m_ReadBuf + xx_read, m_ReadBuf + xx_read);
        }
        n_read += x_read;
        if (m_Status != eIO_Success)
            break;
        buf    += x_read;
        n      -= x_read;
    } while (n);

    return (streamsize) n_read;
}