当前位置: 首页>>代码示例>>C++>>正文


C++ xs_assert函数代码示例

本文整理汇总了C++中xs_assert函数的典型用法代码示例。如果您正苦于以下问题:C++ xs_assert函数的具体用法?C++ xs_assert怎么用?C++ xs_assert使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xs_assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xs_assert

void xs::pipe_t::process_pipe_term_ack ()
{
    //  Notify the user that all the references to the pipe should be dropped.
    xs_assert (sink);
    sink->terminated (this);

    //  In terminating and double_terminated states there's nothing to do.
    //  Simply deallocate the pipe. In terminated state we have to ack the
    //  peer before deallocating this side of the pipe. All the other states
    //  are invalid.
    if (state == terminating) ;
    else if (state == double_terminated);
    else if (state == terminated) {
        outpipe = NULL;
        send_pipe_term_ack (peer);
    }
    else
        xs_assert (false);

    //  We'll deallocate the inbound pipe, the peer will deallocate the outbound
    //  pipe (which is an inbound pipe from its point of view).
    //  First, delete all the unread messages in the pipe. We have to do it by
    //  hand because msg_t doesn't have automatic destructor. Then deallocate
    //  the ypipe itself.
    msg_t msg;
    while (inpipe->read (&msg)) {
       int rc = msg.close ();
       errno_assert (rc == 0);
    }
    delete inpipe;

    //  Deallocate the pipe object
    delete this;
}
开发者ID:adeze,项目名称:libxs,代码行数:34,代码来源:pipe.cpp

示例2: set_pollin

void xs::pgm_receiver_t::activate_in ()
{
    //  It is possible that the most recently used decoder
    //  processed the whole buffer but failed to write
    //  the last message into the pipe.
    if (pending_bytes == 0) {
        if (mru_decoder != NULL) {
            mru_decoder->process_buffer (NULL, 0);
            session->flush ();
        }

        //  Resume polling.
        set_pollin (pipe_handle);
        set_pollin (socket_handle);

        return;
    }

    xs_assert (mru_decoder != NULL);
    xs_assert (pending_ptr != NULL);

    //  Ask the decoder to process remaining data.
    size_t n = mru_decoder->process_buffer (pending_ptr, pending_bytes);
    pending_bytes -= n;
    session->flush ();

    if (pending_bytes > 0)
        return;

    //  Resume polling.
    set_pollin (pipe_handle);
    set_pollin (socket_handle);

    in_event (retired_fd);
}
开发者ID:PiotrSikora,项目名称:libxs,代码行数:35,代码来源:pgm_receiver.cpp

示例3: read

void xs::signaler_recv (xs::signaler_t *self_)
{
    //  Attempt to read a signal.
#if defined XS_HAVE_EVENTFD
    uint64_t dummy;
    ssize_t sz = read (self_->r, &dummy, sizeof (dummy));
    errno_assert (sz == sizeof (dummy));

    //  If we accidentally grabbed the next signal along with the current
    //  one, return it back to the eventfd object.
    if (unlikely (dummy == 2)) {
        const uint64_t inc = 1;
        ssize_t sz = write (self_->w, &inc, sizeof (inc));
        errno_assert (sz == sizeof (inc));
        return;
    }

    xs_assert (dummy == 1);
#else
    unsigned char dummy;
#if defined XS_HAVE_WINDOWS
    int nbytes = ::recv (self_->r, (char*) &dummy, sizeof (dummy), 0);
    wsa_assert (nbytes != SOCKET_ERROR);
#else
    ssize_t nbytes = ::recv (self_->r, &dummy, sizeof (dummy), 0);
    errno_assert (nbytes >= 0);
#endif
    xs_assert (nbytes == sizeof (dummy));
    xs_assert (dummy == 0);
#endif
}
开发者ID:adeze,项目名称:libxs,代码行数:31,代码来源:signaler.cpp

示例4: write

void xs::signaler_send (xs::signaler_t *self_)
{
#if defined XS_HAVE_EVENTFD
    const uint64_t inc = 1;
    ssize_t sz = write (self_->w, &inc, sizeof (inc));
    errno_assert (sz == sizeof (inc));
#elif defined XS_HAVE_WINDOWS
    unsigned char dummy = 0;
    int nbytes = ::send (self_->w, (char*) &dummy, sizeof (dummy), 0);
    wsa_assert (nbytes != SOCKET_ERROR);
    xs_assert (nbytes == sizeof (dummy));
#else
    unsigned char dummy = 0;
    while (true) {
#if defined MSG_NOSIGNAL
        ssize_t nbytes = ::send (self_->w, &dummy, sizeof (dummy),
            MSG_NOSIGNAL);
#else
        ssize_t nbytes = ::send (self_->w, &dummy, sizeof (dummy), 0);
#endif
        if (unlikely (nbytes == -1 && errno == EINTR))
            continue;
        xs_assert (nbytes == sizeof (dummy));
        break;
    }
#endif
}
开发者ID:adeze,项目名称:libxs,代码行数:27,代码来源:signaler.cpp

示例5: xs_assert

void xs::xrep_t::xwrite_activated (pipe_t *pipe_)
{
    for (outpipes_t::iterator it = outpipes.begin ();
          it != outpipes.end (); ++it) {
        if (it->second.pipe == pipe_) {
            xs_assert (!it->second.active);
            it->second.active = true;
            return;
        }
    }
    xs_assert (false);
}
开发者ID:carthagezz,项目名称:libxs,代码行数:12,代码来源:xrep.cpp

示例6: poll

int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
{
#ifdef XS_USE_SYNC_POLL

    struct pollfd pfd;
    pfd.fd = self_->r;
    pfd.events = POLLIN;
    int rc = poll (&pfd, 1, timeout_);
    if (unlikely (rc < 0)) {
        errno_assert (errno == EINTR);
        return -1;
    }
    else if (unlikely (rc == 0)) {
        errno = EAGAIN;
        return -1;
    }
    xs_assert (rc == 1);
    xs_assert (pfd.revents & POLLIN);
    return 0;

#elif defined XS_USE_SYNC_SELECT
    FD_SET (self_->r, &self_->fds);
    struct timeval timeout;
    if (timeout_ >= 0) {
        timeout.tv_sec = timeout_ / 1000;
        timeout.tv_usec = timeout_ % 1000 * 1000;
    }
#ifdef XS_HAVE_WINDOWS
    int rc = select (0, &self_->fds, NULL, NULL,
        timeout_ >= 0 ? &timeout : NULL);
    wsa_assert (rc != SOCKET_ERROR);
#else
    int rc = select (self_->r + 1, &self_->fds, NULL, NULL,
        timeout_ >= 0 ? &timeout : NULL);
    if (unlikely (rc < 0)) {
        errno_assert (errno == EINTR);
        return -1;
    }
#endif
    if (unlikely (rc == 0)) {
        errno = EAGAIN;
        return -1;
    }
    xs_assert (rc == 1);
    return 0;

#else
#error
    return -1;
#endif
}
开发者ID:adeze,项目名称:libxs,代码行数:51,代码来源:signaler.cpp

示例7: xs_assert

size_t xs::msg_t::size ()
{
    //  Check the validity of the message.
    xs_assert (check ());

    switch (u.base.type) {
    case type_vsm:
        return u.vsm.size;
    case type_lmsg:
        return u.lmsg.content->size;
    default:
        xs_assert (false);
        return 0;
    }
}
开发者ID:PiotrSikora,项目名称:libxs,代码行数:15,代码来源:msg.cpp

示例8: xs_assert

void xs::stream_engine_t::error ()
{
    xs_assert (session);
    session->detach ();
    unplug ();
    delete this;
}
开发者ID:adeze,项目名称:libxs,代码行数:7,代码来源:stream_engine.cpp

示例9: accept

void xs::ipc_listener_t::in_event (fd_t fd_)
{
    fd_t fd = accept ();

    //  If connection was reset by the peer in the meantime, just ignore it.
    //  TODO: Handle specific errors like ENFILE/EMFILE etc.
    if (fd == retired_fd)
        return;

    //  Create the engine object for this connection.
    stream_engine_t *engine = new (std::nothrow) stream_engine_t (fd, options);
    alloc_assert (engine);

    //  Choose I/O thread to run connecter in. Given that we are already
    //  running in an I/O thread, there must be at least one available.
    io_thread_t *thread = choose_io_thread (options.affinity);
    xs_assert (thread);

    //  Create and launch a session object. 
    session_base_t *session = session_base_t::create (thread, false, socket,
        options, NULL, NULL);
    errno_assert (session);
    session->inc_seqnum ();
    launch_child (session);
    send_attach (session, engine, false);
}
开发者ID:adeze,项目名称:libxs,代码行数:26,代码来源:ipc_listener.cpp

示例10: xs_assert

xs::socket_base_t::~socket_base_t ()
{
    xs_assert (destroyed);

    if (initialised)
        mailbox_close (&mailbox);
}
开发者ID:carthagezz,项目名称:libxs,代码行数:7,代码来源:socket_base.cpp

示例11: get_filter

int xs::sub_t::xsetsockopt (int option_, const void *optval_,
    size_t optvallen_)
{
    if (option_ != XS_SUBSCRIBE && option_ != XS_UNSUBSCRIBE) {
        errno = EINVAL;
        return -1;
    }

    if (optvallen_ > 0 && !optval_) {
        errno = EFAULT;
        return -1;
    }

    //  Find the relevant filter.
    filters_t::iterator it;
    for (it = filters.begin (); it != filters.end (); ++it)
        if (it->type->id (NULL) == options.filter)
            break;

    //  Process the subscription. If the filter of the specified type does not
    //  exist yet, create it.
    if (option_ == XS_SUBSCRIBE) {
        if (it == filters.end ()) {
            filter_t f;
            f.type = get_filter (options.filter);
            xs_assert (f.type);
            f.instance = f.type->sf_create ((void*) (core_t*) this);
            xs_assert (f.instance);
            filters.push_back (f);
            it = filters.end () - 1;
        }
        int rc = it->type->sf_subscribe ((void*) (core_t*) this, it->instance,
            (const unsigned char*) optval_, optvallen_);
        errno_assert (rc == 0);
        return 0;
    }
    else if (option_ == XS_UNSUBSCRIBE) {
        xs_assert (it != filters.end ());
        int rc = it->type->sf_unsubscribe ((void*) (core_t*) this, it->instance,
            (const unsigned char*) optval_, optvallen_);
        errno_assert (rc == 0);
        return 0;
    }

    xs_assert (false);
    return -1;
}
开发者ID:carthagezz,项目名称:libxs,代码行数:47,代码来源:sub.cpp

示例12: sizeof

void xs::pgm_sender_t::out_event (fd_t fd_)
{
    //  POLLOUT event from send socket. If write buffer is empty, 
    //  try to read new data from the encoder.
    if (write_size == 0) {

        //  First two bytes (sizeof uint16_t) are used to store message 
        //  offset in following steps. Note that by passing our buffer to
        //  the get data function we prevent it from returning its own buffer.
        unsigned char *bf = out_buffer + sizeof (uint16_t);
        size_t bfsz = out_buffer_size - sizeof (uint16_t);
        int offset = -1;
        encoder.get_data (&bf, &bfsz, &offset);

        //  If there are no data to write stop polling for output.
        if (!bfsz) {
            reset_pollout (handle);
            return;
        }

        //  Put offset information in the buffer.
        write_size = bfsz + sizeof (uint16_t);
        put_uint16 (out_buffer, offset == -1 ? 0xffff : (uint16_t) offset);
    }

    if (tx_timer) {
        rm_timer (tx_timer);
        tx_timer = NULL;
    }

    //  Send the data.
    size_t nbytes = pgm_socket.send (out_buffer, write_size);

    //  We can write either all data or 0 which means rate limit reached.
    if (nbytes == write_size) {
        write_size = 0;
    } else {
        xs_assert (nbytes == 0);

        if (errno == ENOMEM) {
            const long timeout = pgm_socket.get_tx_timeout ();
            xs_assert (!tx_timer);
            tx_timer = add_timer (timeout);
        } else
            errno_assert (errno == EBUSY);
    }
}
开发者ID:jianjin,项目名称:libxs,代码行数:47,代码来源:pgm_sender.cpp

示例13: write

void xs::stream_engine_t::out_event (fd_t fd_)
{
    bool more_data = true;

    //  If protocol header was not yet sent...
    if (unlikely (!options.legacy_protocol && !header_sent)) {
        int hbytes = write (out_header, sizeof out_header);

        //  It should always be possible to write the full protocol header to a
        //  freshly connected TCP socket. Therefore, if we get an error or
        //  partial write here the peer has disconnected.
        if (hbytes != sizeof out_header) {
            error ();
            return;
        }
        header_sent = true;
    }

    //  If write buffer is empty, try to read new data from the encoder.
    if (!outsize) {

        outpos = NULL;
        more_data = encoder.get_data (&outpos, &outsize);

        //  If IO handler has unplugged engine, flush transient IO handler.
        if (unlikely (!plugged)) {
            xs_assert (leftover_session);
            leftover_session->flush ();
            return;
        }

        //  If there is no data to send, stop polling for output.
        if (outsize == 0) {
            reset_pollout (handle);
            return;
        }
    }

    //  If there are any data to write in write buffer, write as much as
    //  possible to the socket. Note that amount of data to write can be
    //  arbitratily large. However, we assume that underlying TCP layer has
    //  limited transmission buffer and thus the actual number of bytes
    //  written should be reasonably modest.
    int nbytes = write (outpos, outsize);

    //  Handle problems with the connection.
    if (nbytes == -1) {
        error ();
        return;
    }

    outpos += nbytes;
    outsize -= nbytes;

    //  If the encoder reports that there are no more data to get from it
    //  we can stop polling for POLLOUT immediately.
    if (!more_data && !outsize)
        reset_pollout (handle);
}
开发者ID:adeze,项目名称:libxs,代码行数:59,代码来源:stream_engine.cpp

示例14: xs_assert

void xs::own_t::unregister_term_ack ()
{
    xs_assert (term_acks > 0);
    term_acks--;

    //  This may be a last ack we are waiting for before termination...
    check_term_acks (); 
}
开发者ID:PiotrSikora,项目名称:libxs,代码行数:8,代码来源:own.cpp

示例15: xs_assert

void xs::xrespondent_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
{
    xs_assert (pipe_);

    //  Add the pipe to the map out outbound pipes.
    outpipe_t outpipe = {pipe_, true};
    bool ok = outpipes.insert (outpipes_t::value_type (
        next_peer_id, outpipe)).second;
    xs_assert (ok);

    //  Add the pipe to the list of inbound pipes.
    blob_t identity (4, 0);
    put_uint32 ((unsigned char*) identity.data (), next_peer_id);
    pipe_->set_identity (identity);
    fq.attach (pipe_);

    //  Generate a new unique peer identity.
    ++next_peer_id;    
}
开发者ID:carthagezz,项目名称:libxs,代码行数:19,代码来源:xrespondent.cpp


注:本文中的xs_assert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。