Exemplo n.º 1
0
void SaslConnection::close()
{
    Endpoint client = peer();
    Connection::close();

    if ( !u || logged ||
         !client.valid() || client.protocol() == Endpoint::Unix )
        return;

    logged = true;

    Query * q = new Query(
        "insert into connections "
        "(username,address,port,mechanism,authfailures,"
        "syntaxerrors,started_at,ended_at,userid) "
        "values ($1,$2,$3,$4,$5,$6,"
        "$7::interval + 'epoch'::timestamptz,"
        "$8::interval + 'epoch'::timestamptz,$9)", 0
    );

    q->bind( 1, u->login() );
    q->bind( 2, client.address() );
    q->bind( 3, client.port() );
    q->bind( 4, m );
    q->bind( 5, af );
    q->bind( 6, sf );
    q->bind( 7, s );
    q->bind( 8, (uint)time( 0 ) );
    q->bind( 9, u->id() );
    q->execute();

}
Exemplo n.º 2
0
int Connection::connect( const Endpoint &e )
{
    if ( !e.valid() )
        return -1;

    if ( !valid() ) {
        init( socket( e.protocol() ) );
        if ( !valid() )
            return -1;
    }

    int n = ::connect( d->fd, e.sockaddr(), e.sockaddrSize() );

    d->pending = false;
    setState( Connecting );
    if ( n == 0 || ( n < 0 && errno == EINPROGRESS ) ) {
        if ( n == 0 ) {
            d->event = Connect;
            d->pending = true;
        }
        n = 1;
    }
    else {
        d->event = Error;
        d->pending = true;
        n = -1;
    }

    return n;
}
Exemplo n.º 3
0
            void resolve_no_block(
                implementation_type & impl, 
                NetName const & name, 
                error_code & ec)
            {
                Endpoint svc;
                svc_cache_.find(name, svc, ec);
                if (ec) {
                    impl->ec = ec;
                    impl->state = ResolveTask::finished;
                    return;
                }
                // 可能service只有一种
                impl->name = name;
                impl->name.protocol((NetName::ProtocolEnum)svc.protocol());
                impl->endpoints.clear();
                impl->ec.clear();
                bool found = host_cache_.find(impl->name, impl->endpoints);
                if (found) {
                    for (size_t i = 0; i < impl->endpoints.size(); ++i) {
                        impl->endpoints[i].port(svc.port());
                    }
                } else {
                    ec = boost::asio::error::would_block;
                }
#ifndef FRAMEWORK_NETWORK_WITH_SERVICE_CACHE
                impl->name.svc(format(svc.port()));
#endif
                impl->state = ResolveTask::waiting;
                tasks_.push_back(impl);
                if (tasks_.size() == 1 && tasks2_.empty()) {
                    sync_data_->cond.notify_one();
                }
            }
Exemplo n.º 4
0
int Connection::listen( const Endpoint &e, bool silent )
{
    if ( !e.valid() )
        return -1;

    if ( !valid() ) {
        init( socket( e.protocol() ) );
        if ( !valid() )
            return -1;
    }

    int i = 1;
    ::setsockopt( d->fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (int) );

    if ( e.protocol() == Endpoint::Unix )
        unlink( File::chrooted( e.address() ).cstr() );

    int retcode = ::bind( d->fd, e.sockaddr(), e.sockaddrSize() );
    if ( retcode < 0 ) {
        if ( errno == EADDRINUSE ) {
            if ( !silent )
                log( "Cannot listen to " +
                     e.address() + " port " + fn( e.port() ) +
                     " because another process is occupying it", Log::Error );
            return -1;
        }
        if ( !silent )
            log( "bind( " + fn( d->fd ) + ", " +
                 e.address() + " port " + fn( e.port() ) +
                 " ) returned errno " + fn( errno ), Log::Debug );
        return -1;
    }
    if ( ::listen( d->fd, 64 ) < 0 ) {
        if ( !silent )
            log( "listen( " + fn( d->fd ) + ", 64 ) for address " +
                 e.address() + " port " + fn( e.port() ) +
                 " ) returned errno " + fn( errno ), Log::Debug );
        return -1;
    }

    setState( Listening );
    d->self = e;
    return 1;
}
Exemplo n.º 5
0
 basic_endpoint(const Endpoint& endpoint)
   : impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol())
 {
 }