Exemplo n.º 1
0
void ErrorCodeTest::TestErrorCode() {
    ErrorCode errorCode;
    if(errorCode.get()!=U_ZERO_ERROR || !errorCode.isSuccess() || errorCode.isFailure()) {
        errln("ErrorCode did not initialize properly");
        return;
    }
    errorCode.assertSuccess();
    if(errorCode.errorName()!=u_errorName(U_ZERO_ERROR)) {
        errln("ErrorCode did not format error message string properly");
    }
    RefPlusOne(errorCode);
    if(errorCode.get()!=U_ILLEGAL_ARGUMENT_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
        errln("ErrorCode did not yield a writable reference");
    }
    PtrPlusTwo(errorCode);
    if(errorCode.get()!=U_INVALID_FORMAT_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
        errln("ErrorCode did not yield a writable pointer");
    }
    errorCode.set(U_PARSE_ERROR);
    if(errorCode.get()!=U_PARSE_ERROR || errorCode.isSuccess() || !errorCode.isFailure()) {
        errln("ErrorCode.set() failed");
    }
    if( errorCode.reset()!=U_PARSE_ERROR || errorCode.get()!=U_ZERO_ERROR ||
        !errorCode.isSuccess() || errorCode.isFailure()
    ) {
        errln("ErrorCode did not reset properly");
    }
}
Exemplo n.º 2
0
bool SQLiteStatement::step(ErrorCode & ec)
{
#if !defined(__APPLE__) && !defined(MLOG_NO_LOGGING)
    mstd::performance_timer ptimer;
#endif
    int err = sqlite3_step(handle_);
#if !defined(__APPLE__) && !defined(MLOG_NO_LOGGING)
    uint64_t cur = ptimer.microseconds();
    if(cur > 100000)
        MLOG_MESSAGE(Warning, "Slow query: " << cur << ", sql: " << sql_);
#endif
    if(err == SQLITE_ROW)
    {
        ec.reset(0, std::string());
        return true;
    } else if(err == SQLITE_DONE)
    {
        ec.reset(0, std::string());
        return false;
    } else {
        resetEC(ec, err, db_.handle());
        return false;
    }
}
Exemplo n.º 3
0
    virtual bool onAcceptable(ErrorCode* ec)
    {
        ErrorCode tmpec;

        for (;;)
        {
            tmpec.reset();

            struct sockaddr_storage ss;
            socklen_t socklen = sizeof(ss);
            int new_fd = ::accept(fd(), (struct sockaddr*)&ss, &socklen);
            if (-1 == new_fd)
                break;

            if (0 == socklen)
            {
                SocketHelper::closeSocket(new_fd, &tmpec);
                continue;
            }

            SockAddr addr((struct sockaddr*)&ss, socklen);

            if (addr.getType() == AF_UNIX)
            {
                if (!checkUnixDomain(addr))
                {
                    SocketHelper::closeSocket(new_fd, &tmpec);
                    continue;
                }
            }

            try
            {
            	onAccept(new_fd, addr);
            }
            catch (...)
            {
            }
        }
        return true;
    }
Exemplo n.º 4
0
void resetEC(ErrorCode & ec, int err, sqlite3 * handle)
{
    ec.reset(err, (err == SQLITE_OK || !handle) ? std::string() : sqlite3_errmsg(handle));
}