示例#1
0
文件: Poll.cpp 项目: ClickSmile/httpd
void Poll::addFD(SocketPtr sock, PollHandler handler)
{
	static struct epoll_event ev;

	{
		std::unique_lock<std::mutex> lock(mutex_);
		handlers_[sock->native()] = std::make_tuple(sock, handler);
	}

	ev.events = /*EPOLLET |*/ EPOLLIN | EPOLLOUT;
	ev.data.fd = sock->native();

	int ret = epoll_ctl(fd_, EPOLL_CTL_ADD, sock->native(), &ev);
	if (ret != 0)
	{
		THROW_SYSTEM_ERROR();
	}
}
示例#2
0
void
SocketAdapter::handleOperations(SocketPtr s, curl_socket_t theCurlSocket) {
    AC_TRACE << "handleOperations: socket " << theCurlSocket << " is " << s->readyState;
    if (!s->boost_socket.is_open()) {
        return;
    }
    // NOTE: this will be called from one of io_service's threads
    switch (s->readyState) {
        case CURL_POLL_OUT:
            if (s->write_in_progress == false) {
                s->write_in_progress = true;
                AC_TRACE << "queuing write " << s->native();
                s->boost_socket.async_write_some(
                        boost::asio::null_buffers(),
                        s->_parent->_strand.wrap(
                        boost::bind(&SocketAdapter::handleWrite, s,
                            boost::asio::placeholders::error)));
            }
            break;
        case CURL_POLL_IN:
            if (s->read_in_progress == false) {
                s->read_in_progress = true;
                AC_TRACE << "queuing read " << s->native();
                s->boost_socket.async_read_some(
                        boost::asio::null_buffers(),
                        s->_parent->_strand.wrap(
                        boost::bind(&SocketAdapter::handleRead, s,
                            boost::asio::placeholders::error)));

            }
            break;
        case CURL_POLL_REMOVE:
            // we don't need to do anything here. We'll keep the connection open 
            // so it can be reused by later clients
            break;
        default:
            throw asl::Exception("Unknown Socket State "+s->readyState); 
    };
}