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


C++ MORDOR_ASSERT函数代码示例

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


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

示例1: MORDOR_ASSERT

void
FiberMutex::lock()
{
    MORDOR_ASSERT(Scheduler::getThis());
    {
        boost::mutex::scoped_lock scopeLock(m_mutex);
        MORDOR_ASSERT(m_owner != Fiber::getThis());
        MORDOR_ASSERT(std::find(m_waiters.begin(), m_waiters.end(),
            std::make_pair(Scheduler::getThis(), Fiber::getThis()))
            == m_waiters.end());
        if (!m_owner) {
            m_owner = Fiber::getThis();
            return;
        }
        m_waiters.push_back(std::make_pair(Scheduler::getThis(),
            Fiber::getThis()));
    }
    Scheduler::yieldTo();
#ifdef DEBUG
    boost::mutex::scoped_lock scopeLock(m_mutex);
    MORDOR_ASSERT(m_owner == Fiber::getThis());
    MORDOR_ASSERT(std::find(m_waiters.begin(), m_waiters.end(),
            std::make_pair(Scheduler::getThis(), Fiber::getThis()))
            == m_waiters.end());
#endif
}
开发者ID:Abioy,项目名称:mordor,代码行数:26,代码来源:fibersynchronization.cpp

示例2: Scheduler

IOManagerEPoll::IOManagerEPoll(int threads, bool useCaller)
    : Scheduler(threads, useCaller)
{
    m_epfd = epoll_create(5000);
    MORDOR_LOG_LEVEL(g_log, m_epfd <= 0 ? Log::ERROR : Log::TRACE) << this
        << " epoll_create(5000): " << m_epfd;
    if (m_epfd <= 0)
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("epoll_create");
    int rc = pipe(m_tickleFds);
    MORDOR_LOG_LEVEL(g_log, rc ? Log::ERROR : Log::VERBOSE) << this << " pipe(): "
        << rc << " (" << errno << ")";
    if (rc) {
        close(m_epfd);
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("pipe");
    }
    MORDOR_ASSERT(m_tickleFds[0] > 0);
    MORDOR_ASSERT(m_tickleFds[1] > 0);
    epoll_event event;
    event.events = EPOLLIN;
    event.data.fd = m_tickleFds[0];
    rc = epoll_ctl(m_epfd, EPOLL_CTL_ADD, m_tickleFds[0], &event);
    MORDOR_LOG_LEVEL(g_log, rc ? Log::ERROR : Log::VERBOSE) << this
        << " epoll_ctl(" << m_epfd << ", EPOLL_CTL_ADD, " << m_tickleFds[0]
        << ", EPOLLIN): " << rc << " (" << errno << ")";
    if (rc) {
        close(m_tickleFds[0]);
        close(m_tickleFds[1]);
        close(m_epfd);
        MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("epoll_ctl");
    }
}
开发者ID:adfin,项目名称:mordor,代码行数:31,代码来源:iomanager_epoll.cpp

示例3: while

size_t
SSLStream::read(void *buffer, size_t length)
{
    const int toRead = (int)std::min<size_t>(0x0fffffff, length);
    while (true) {
        unsigned long error = SSL_ERROR_NONE;
        const int result = sslCallWithLock(std::bind(SSL_read, m_ssl.get(), buffer, toRead), &error);
        if (result > 0) {
            return result;
        }
        MORDOR_LOG_DEBUG(g_log) << this << " SSL_read(" << m_ssl.get() << ", "
            << toRead << "): " << result << " (" << error << ")";
        switch (error) {
            case SSL_ERROR_NONE:
                return result;
            case SSL_ERROR_ZERO_RETURN:
                // Received close_notify message
                MORDOR_ASSERT(result == 0);
                return 0;
            case SSL_ERROR_WANT_READ:
                wantRead();
                continue;
            case SSL_ERROR_WANT_WRITE:
            case SSL_ERROR_WANT_CONNECT:
            case SSL_ERROR_WANT_ACCEPT:
            case SSL_ERROR_WANT_X509_LOOKUP:
                MORDOR_NOTREACHED();
            case SSL_ERROR_SYSCALL:
                if (hasOpenSSLError()) {
                    std::string message = getOpenSSLErrorMessage();
                    MORDOR_LOG_ERROR(g_log) << this << " SSL_read("
                        << m_ssl.get() << ", " << toRead << "): " << result
                        << " (" << error << ", " << message << ")";
                    MORDOR_THROW_EXCEPTION(OpenSSLException(message))
                       // << boost::errinfo_api_function("SSL_read");
                    ;
                }
                MORDOR_LOG_WARNING(g_log) << this << " SSL_read("
                    << m_ssl.get() << ", " << toRead << "): " << result
                    << " (" << error << ")";
                if (result == 0) {
                    return 0;
                }
                MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SSL_read");
            case SSL_ERROR_SSL:
                {
                    MORDOR_ASSERT(hasOpenSSLError());
                    std::string message = getOpenSSLErrorMessage();
                    MORDOR_LOG_ERROR(g_log) << this << " SSL_read("
                        << m_ssl.get() << ", " << toRead << "): " << result
                        << " (" << error << ", " << message << ")";
                    MORDOR_THROW_EXCEPTION(OpenSSLException(message))
                      //  << boost::errinfo_api_function("SSL_read");
                    ;
                }
            default:
                MORDOR_NOTREACHED();
        }
    }
}
开发者ID:zalemwoo,项目名称:mordor-base,代码行数:60,代码来源:ssl.cpp

示例4: MORDOR_ASSERT

void
Buffer::truncate(size_t length)
{
    MORDOR_ASSERT(length <= readAvailable());
    if (length == m_readAvailable)
        return;
    // Split any mixed read/write bufs
    if (m_writeIt != m_segments.end() && m_writeIt->readAvailable() != 0) {
        m_segments.insert(m_writeIt, Segment(m_writeIt->readBuffer()));
        m_writeIt->consume(m_writeIt->readAvailable());
    }
    m_readAvailable = length;
    std::list<Segment>::iterator it;
    for (it = m_segments.begin(); it != m_segments.end() && length > 0; ++it) {
        Segment &segment = *it;
        if (length <= segment.readAvailable()) {
            segment.truncate(length);
            length = 0;
            ++it;
            break;
        } else {
            length -= segment.readAvailable();
        }
    }
    MORDOR_ASSERT(length == 0);
    while (it != m_segments.end() && it->readAvailable() > 0) {
        MORDOR_ASSERT(it->writeAvailable() == 0);
        it = m_segments.erase(it);
    }
    invariant();
}
开发者ID:fathomdb,项目名称:mordor,代码行数:31,代码来源:buffer.cpp

示例5: lock

void
FiberCondition::broadcast()
{
    boost::mutex::scoped_lock lock(m_mutex);
    if (m_waiters.empty())
        return;
    boost::mutex::scoped_lock lock2(m_fiberMutex.m_mutex);

    std::list<std::pair<Scheduler *, Fiber::ptr> >::iterator it;
    for (it = m_waiters.begin();
        it != m_waiters.end();
        ++it) {
        std::pair<Scheduler *, Fiber::ptr> &next = *it;
        MORDOR_ASSERT(m_fiberMutex.m_owner != next.second);
        MORDOR_ASSERT(std::find(m_fiberMutex.m_waiters.begin(),
            m_fiberMutex.m_waiters.end(), next)
            == m_fiberMutex.m_waiters.end());
        if (!m_fiberMutex.m_owner) {
            m_fiberMutex.m_owner = next.second;
            next.first->schedule(next.second);
        } else {
            m_fiberMutex.m_waiters.push_back(next);
        }
    }
    m_waiters.clear();
}
开发者ID:Abioy,项目名称:mordor,代码行数:26,代码来源:fibersynchronization.cpp

示例6: while

int
Buffer::opCmp(const Buffer &rhs) const
{
    std::list<Segment>::const_iterator leftIt, rightIt;
    int lengthResult = (int)((ptrdiff_t)readAvailable() - (ptrdiff_t)rhs.readAvailable());
    leftIt = m_segments.begin(); rightIt = rhs.m_segments.begin();
    size_t leftOffset = 0, rightOffset = 0;
    while (leftIt != m_segments.end() && rightIt != rhs.m_segments.end())
    {
        MORDOR_ASSERT(leftOffset <= leftIt->readAvailable());
        MORDOR_ASSERT(rightOffset <= rightIt->readAvailable());
        size_t tocompare = (std::min)(leftIt->readAvailable() - leftOffset,
            rightIt->readAvailable() - rightOffset);
        if (tocompare == 0)
            break;
        int result = memcmp(
            (const unsigned char *)leftIt->readBuffer().start() + leftOffset,
            (const unsigned char *)rightIt->readBuffer().start() + rightOffset,
            tocompare);
        if (result != 0)
            return result;
        leftOffset += tocompare;
        rightOffset += tocompare;
        if (leftOffset == leftIt->readAvailable()) {
            leftOffset = 0;
            ++leftIt;
        }
        if (rightOffset == rightIt->readAvailable()) {
            rightOffset = 0;
            ++rightIt;
        }
    }
    return lengthResult;
}
开发者ID:fathomdb,项目名称:mordor,代码行数:34,代码来源:buffer.cpp

示例7: readAvailable

const std::vector<iovec>
Buffer::readBuffers(size_t length) const
{
    if (length == (size_t)~0)
        length = readAvailable();
    MORDOR_ASSERT(length <= readAvailable());
    std::vector<iovec> result;
    result.reserve(m_segments.size());
    size_t remaining = length;
    std::list<Segment>::const_iterator it;
    for (it = m_segments.begin(); it != m_segments.end(); ++it) {
        size_t toConsume = (std::min)(it->readAvailable(), remaining);
        SegmentData data = it->readBuffer().slice(0, toConsume);
#ifdef WINDOWS
        while (data.length() > 0) {
            iovec wsabuf;
            wsabuf.iov_base = (void *)data.start();
            wsabuf.iov_len = iovLength(data.length());
            result.push_back(wsabuf);
            data = data.slice(wsabuf.iov_len);
        }
#else
        iovec iov;
        iov.iov_base = (void *)data.start();
        iov.iov_len = data.length();
        result.push_back(iov);
#endif
        remaining -= toConsume;
        if (remaining == 0)
            break;
    }
    MORDOR_ASSERT(remaining == 0);
    invariant();
    return result;
}
开发者ID:fathomdb,项目名称:mordor,代码行数:35,代码来源:buffer.cpp

示例8: flushBuffer

void
ZlibStream::flush(int flush)
{
    flushBuffer();
    while (true) {
        if (m_outBuffer.writeAvailable() == 0)
            m_outBuffer.reserve(m_bufferSize);
        struct iovec outbuf = m_outBuffer.writeBuffer(~0u, false);
        MORDOR_ASSERT(m_strm.avail_in == 0);
        m_strm.next_out = (Bytef*)outbuf.iov_base;
        m_strm.avail_out = outbuf.iov_len;
        int rc = deflate(&m_strm, flush);
        MORDOR_ASSERT(m_strm.avail_in == 0);
        MORDOR_LOG_DEBUG(g_log) << this << " deflate((0, " << outbuf.iov_len
            << "), " << flush << "): " << rc << " (0, " << m_strm.avail_out
            << ")";
        m_outBuffer.produce(outbuf.iov_len - m_strm.avail_out);
        MORDOR_ASSERT(flush == Z_FINISH || rc != Z_STREAM_END);
        switch (rc) {
            case Z_STREAM_END:
                m_closed = true;
                deflateEnd(&m_strm);
                flushBuffer();
                return;
            case Z_OK:
                break;
            case Z_BUF_ERROR:
                flushBuffer();
                return;
            default:
                MORDOR_NOTREACHED();
        }
    }
}
开发者ID:Abioy,项目名称:mordor,代码行数:34,代码来源:zlib.cpp

示例9: scopeLock

FiberMutex::~FiberMutex()
{
#ifdef DEBUG
    boost::mutex::scoped_lock scopeLock(m_mutex);
    MORDOR_ASSERT(!m_owner);
    MORDOR_ASSERT(m_waiters.empty());
#endif
}
开发者ID:Abioy,项目名称:mordor,代码行数:8,代码来源:fibersynchronization.cpp

示例10: MORDOR_THROW_EXCEPTION

void
Buffer::copyIn(const Buffer &buffer, size_t length, size_t pos)
{
    if (pos > buffer.readAvailable())
        MORDOR_THROW_EXCEPTION(std::out_of_range("position out of range"));

    if (length == (size_t)~0)
        length = buffer.readAvailable() - pos;
    MORDOR_ASSERT(buffer.readAvailable() >= length + pos);
    invariant();
    if (length == 0)
        return;

    // Split any mixed read/write bufs
    if (m_writeIt != m_segments.end() && m_writeIt->readAvailable() != 0) {
        m_segments.insert(m_writeIt, Segment(m_writeIt->readBuffer()));
        m_writeIt->consume(m_writeIt->readAvailable());
        invariant();
    }

    std::list<Segment>::const_iterator it = buffer.m_segments.begin();
    while (pos != 0 && it != buffer.m_segments.end()) {
        if (pos < it->readAvailable())
            break;
        pos -= it->readAvailable();
        ++it;
    }
    MORDOR_ASSERT(it != buffer.m_segments.end());
    for (; it != buffer.m_segments.end(); ++it) {
        size_t toConsume = (std::min)(it->readAvailable() - pos, length);
        if (m_readAvailable != 0 && it == buffer.m_segments.begin()) {
            std::list<Segment>::iterator previousIt = m_writeIt;
            --previousIt;
            if ((char *)previousIt->readBuffer().start() +
                previousIt->readBuffer().length() == (char *)it->readBuffer().start() + pos &&
                previousIt->m_data.m_array.get() == it->m_data.m_array.get()) {
                MORDOR_ASSERT(previousIt->writeAvailable() == 0);
                previousIt->extend(toConsume);
                m_readAvailable += toConsume;
                length -= toConsume;
                pos = 0;
                if (length == 0)
                    break;
                continue;
            }
        }
        Segment newSegment = Segment(it->readBuffer().slice(pos, toConsume));
        m_segments.insert(m_writeIt, newSegment);
        m_readAvailable += toConsume;
        length -= toConsume;
        pos = 0;
        if (length == 0)
            break;
    }
    MORDOR_ASSERT(length == 0);
    MORDOR_ASSERT(readAvailable() >= length);
}
开发者ID:fathomdb,项目名称:mordor,代码行数:57,代码来源:buffer.cpp

示例11: MORDOR_ASSERT

void
Multipart::finish()
{
    MORDOR_ASSERT(m_stream->supportsWrite());
    MORDOR_ASSERT(!m_finished);
    std::string finalBoundary = m_boundary + "--\r\n";
    m_stream->write(finalBoundary.c_str(), finalBoundary.size());
    m_finished = true;
    if (multipartFinished)
        multipartFinished();
}
开发者ID:adfin,项目名称:mordor,代码行数:11,代码来源:multipart.cpp

示例12: m_stream

Connection::Connection(Stream::ptr stream)
: m_stream(stream)
{
    MORDOR_ASSERT(stream);
    MORDOR_ASSERT(stream->supportsRead());
    MORDOR_ASSERT(stream->supportsWrite());
    if (!stream->supportsUnread() || !stream->supportsFind()) {
        BufferedStream *buffered = new BufferedStream(stream);
        buffered->allowPartialReads(true);
        m_stream.reset(buffered);
    }
}
开发者ID:Abioy,项目名称:mordor,代码行数:12,代码来源:connection.cpp

示例13: MORDOR_ASSERT

void
Scheduler::yieldTo(bool yieldToCallerOnTerminate)
{
    MORDOR_ASSERT(t_fiber.get());
    MORDOR_ASSERT(Scheduler::getThis() == this);
    if (yieldToCallerOnTerminate)
        MORDOR_ASSERT(m_rootThread == gettid());
    if (t_fiber->state() != Fiber::HOLD) {
        m_stopping = m_autoStop || m_stopping;
        t_fiber->reset();
    }
    t_fiber->yieldTo(yieldToCallerOnTerminate);
}
开发者ID:Abioy,项目名称:mordor,代码行数:13,代码来源:scheduler.cpp

示例14: MORDOR_ASSERT

Stream::ptr
Connection::getStream(const GeneralHeaders &general,
    const EntityHeaders &entity, const std::string &method, Status status,
    boost::function<void()> notifyOnEof,
    boost::function<void()> notifyOnException, bool forRead)
{
    MORDOR_ASSERT(hasMessageBody(general, entity, method, status));
    Stream::ptr stream;
    if (forRead) {
        stream.reset(new SingleplexStream(m_stream, SingleplexStream::READ, false));
    } else {
        stream.reset(new SingleplexStream(m_stream, SingleplexStream::WRITE, false));
    }
    Stream::ptr baseStream(stream);
    for (ParameterizedList::const_reverse_iterator it(general.transferEncoding.rbegin());
        it != general.transferEncoding.rend();
        ++it) {
        if (stricmp(it->value.c_str(), "chunked") == 0) {
            stream.reset(new ChunkedStream(stream));
        } else if (stricmp(it->value.c_str(), "deflate") == 0) {
            stream.reset(new ZlibStream(stream));
        } else if (stricmp(it->value.c_str(), "gzip") == 0 ||
            stricmp(it->value.c_str(), "x-gzip") == 0) {
            stream.reset(new GzipStream(stream));
        } else if (stricmp(it->value.c_str(), "compress") == 0 ||
            stricmp(it->value.c_str(), "x-compress") == 0) {
            MORDOR_ASSERT(false);
        } else if (stricmp(it->value.c_str(), "identity") == 0) {
            MORDOR_ASSERT(false);
        } else {
            MORDOR_ASSERT(false);
        }
    }
    if (stream != baseStream) {
    } else if (entity.contentLength != ~0ull) {
        LimitedStream::ptr limited(new LimitedStream(stream, entity.contentLength));
        limited->strict(true);
        stream = limited;
    } else if (entity.contentType.type == "multipart") {
        // Getting stream to pass to multipart; self-delimiting
    } else {
        // Delimited by closing the connection
    }
    NotifyStream::ptr notify(new NotifyStream(stream));
    stream = notify;
    notify->notifyOnClose = notifyOnEof;
    notify->notifyOnEof = notifyOnEof;
    notify->notifyOnException = notifyOnException;
    return stream;
}
开发者ID:Abioy,项目名称:mordor,代码行数:50,代码来源:connection.cpp

示例15: m_stream

Multipart::Multipart(Stream::ptr stream, std::string boundary)
: m_stream(stream),
  m_boundary(boundary),
  m_finished(false)
{
    MORDOR_ASSERT(m_stream);
    MORDOR_ASSERT(m_stream->supportsRead() || m_stream->supportsWrite());
    MORDOR_ASSERT(!(m_stream->supportsRead() && m_stream->supportsWrite()));
    while (!m_boundary.empty() && m_boundary[m_boundary.size() - 1] == ' ')
        m_boundary.resize(m_boundary.size() - 1);
    MORDOR_ASSERT(!m_boundary.empty());
    MORDOR_ASSERT(m_boundary.size() <= 70);
    if (m_boundary.find_first_not_of(allowedBoundaryChars) != std::string::npos) {
        if (stream->supportsWrite()) {
            MORDOR_ASSERT(false);
        } else {
            MORDOR_THROW_EXCEPTION(InvalidMultipartBoundaryException());
        }
    }
    m_boundary = "\r\n--" + m_boundary;
    if (m_stream->supportsRead()) {
        MORDOR_ASSERT(m_stream->supportsFind());
        MORDOR_ASSERT(m_stream->supportsUnread());
    }
}
开发者ID:adfin,项目名称:mordor,代码行数:25,代码来源:multipart.cpp


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