예제 #1
0
void connectProc(aioInfo *info)
{
  SSLOp *Op = (SSLOp*)info->arg;
  SSLSocket *S = Op->info.socket;
  if (info->status == aosSuccess) {
    if (Op->state == sslStReadNewFrame) {
      BIO_write(S->bioIn, S->sslReadBuffer, info->bytesTransferred);
      Op->state = sslStConnecting;
    }

    int connectResult = SSL_connect(S->ssl);
    int errCode = SSL_get_error(S->ssl, connectResult);
    if (connectResult == 1) {
      // Successfully connected
      finishSSLOp(Op, aosSuccess);
    } else if (errCode == SSL_ERROR_WANT_READ) {
      // Need data exchange
      size_t connectSize = copyFromOut(S, Op);
      Op->state = sslStReadNewFrame;
      asyncWrite(S->object, Op->sslBuffer, connectSize, afNone, 3000000, 0, 0);
      asyncRead(S->object, S->sslReadBuffer, S->sslReadBufferSize, afNone, 3000000, connectProc, Op);
    } else {
      finishSSLOp(Op, aosUnknownError);          
    }
  } else {
    finishSSLOp(Op, info->status);
  }
}
예제 #2
0
        void Connection::handleWrite(const boost::system::error_code& e ,  size_t  len , int i){


            ++writtenMessages_;
            lastWriteTime_ = time(NULL);
            resetTimer();
            if(!e){
                ioHandlerPtr_->messageSent(shared_from_this(), writeJobQueue_.front());
            } else {
                ioHandlerPtr_->exceptionCaught(shared_from_this(), e);
                LOG_WARN("Connection::handleWrite => sysWrite failure : cid = %d, error = %s" , id_ ,e.message().c_str());
            }

            // 检查是否还有待发送消息,如果有合并发送直到队列为空
            ScopedLock lock(writeJobQueueMutex_);

            // 弹出队首(已经发送完毕)
            if(writeJobQueue_.empty()){
                isWriting_ = false;
                return ;
            }
            writeJobQueue_.pop();

            if (!writeJobQueue_.empty()){
                asyncWrite(writeJobQueue_.front());
            } else {
                isWriting_=false;
            }
        }
예제 #3
0
        bool Connection::write(const string& message){
            //LOG_DEBUG("Connection::write => begin = " << id_);

            if(message.empty() /*|| (message == " ")*/){
                return true;
            }

            if(!isConnected_){
                return false;
            }

            // 得到锁,并把队列里的所有消息合并发送
            ScopedLock lock(writeJobQueueMutex_);

            writeJobQueue_.push(message);

            // 正在写,直接返回,数据已经在队列中,
            // 本次写完成后将被调度
            if(isWriting_){
                return true;
            }else{
                isWriting_ = true ;
            }

            return asyncWrite(writeJobQueue_.front());

        }
예제 #4
0
int eDVBRecordFileThread::writeData(int len)
{
	len = asyncWrite(len);
	if (len < 0)
		return len;
	// Wait for previous aio to complete on this buffer before returning
	int r = m_current_buffer->wait();
	if (r < 0)
		return -1;
	return len;
}
예제 #5
0
파일: chatclient.cpp 프로젝트: azat/twosome
void ChatClient::handleReadInput(const boost::system::error_code& error,
                                 size_t length)
{
    if (error) {
        close();
        return;
    }

    m_inputBuffer.sgetn(m_buffer, length);
    asyncWrite(m_buffer);
}
예제 #6
0
void sslWrite(SSLSocket *socket,
              void *buffer,
              size_t size,
              AsyncFlags flags,
              uint64_t usTimeout,
              sslCb callback,
              void *arg)
{
  SSL_write(socket->ssl, buffer, size);
  SSLOp *newOp = allocSSLOp(socket, callback, arg, buffer, size, afNone);  
  size_t writeSize = copyFromOut(socket, newOp);  
  newOp->type = sslOpWrite;
  asyncWrite(socket->object, newOp->sslBuffer, writeSize, afWaitAll, usTimeout, writeProc, newOp);    
}
예제 #7
0
void BasicConnection::send( std::string&& message, SendCallback callback ){
    // Write the message asynchronously.
    const BufferMap::key_type bufferId = ++m_bufferCounter;
    asyncWrite(
        m_bufferMap[ bufferId ].swapData( message ),
        std::bind(
            &BasicConnection::_sendComplete,
            shared_from_this(),
            bufferId,
            callback,
            std::placeholders::_1,
            std::placeholders::_2
        )
    );
}
예제 #8
0
int eDVBRecordStreamThread::writeData(int len)
{
	len = asyncWrite(len);
	if (len < 0)
		return len;
	// Cancel aio on this buffer before returning, streams should not be held up. So we CANCEL
	// any request that hasn't finished on the second round.
	int r = m_current_buffer->cancel(m_fd_dest);
	switch (r)
	{
		//case 0: // that's one of these two:
		case AIO_CANCELED:
		case AIO_ALLDONE:
			break;
		case AIO_NOTCANCELED:
			eDebug("[eDVBRecordStreamThread] failed to cancel, killing all waiting IO");
			aio_cancel(m_fd_dest, NULL);
			// Poll all open requests, because they are all in error state now.
			for (AsyncIOvector::iterator it = m_aio.begin(); it != m_aio.end(); ++it)
			{
				it->poll();
			}
			break;
		case -1:
			eDebug("[eDVBRecordStreamThread] failed: %m");
			return r;
	}
	// we want to have a consistent state, so wait for completion, just to be sure
	r = m_current_buffer->wait();
	if (r < 0)
	{
		eDebug("[eDVBRecordStreamThread] wait failed: %m");
		return -1;
	}
	return len;
}
예제 #9
0
void KConnectionSelectable::write(KHttpRequest *rq,resultEvent result,bufferEvent buffer)
{
	rq->c->selector->addList(rq,KGL_LIST_RW);
	
	asyncWrite(rq,result,buffer);
}