コード例 #1
0
ファイル: connection.cpp プロジェクト: angeliker/OTHire
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
	#ifdef __DEBUG_NET_DETAIL__
	std::cout << "onWriteOperation" << std::endl;
	#endif

	m_connectionLock.lock();
	m_writeTimer.cancel();

	TRACK_MESSAGE(msg);
	msg.reset();

	if(error){
		handleWriteError(error);
	}

	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError){
		closeSocket();
		closeConnection();
		m_connectionLock.unlock();
		return;
	}

	--m_pendingWrite;
	m_connectionLock.unlock();
}
コード例 #2
0
ファイル: TCPPipe.cpp プロジェクト: Doc-Ok/OpticalTracking
void TCPPipeMaster::writeData(const IO::File::Byte* buffer,size_t bufferSize)
	{
	/* Collect error codes: */
	int errorType=0;
	int errorCode=0;
	
	while(bufferSize>0)
		{
		ssize_t writeResult=::write(fd,buffer,bufferSize);
		if(writeResult>0)
			{
			/* Prepare to write more data: */
			buffer+=writeResult;
			bufferSize-=writeResult;
			}
		else if(errno==EPIPE)
			{
			/* Other side hung up: */
			errorType=1;
			break;
			}
		else if(writeResult<0&&(errno==EAGAIN||errno==EWOULDBLOCK||errno==EINTR))
			{
			/* Do nothing and try again */
			}
		else if(writeResult==0)
			{
			/* Sink has reached end-of-file: */
			errorType=2;
			errorCode=int(bufferSize);
			break;
			}
		else
			{
			/* Unknown error; probably a bad thing: */
			errorType=3;
			errorCode=errno;
			break;
			}
		}
	
	if(isWriteCoupled())
		{
		/* Send a status packet to the slaves: */
		Packet* packet=multiplexer->newPacket();
		{
		Packet::Writer writer(packet);
		writer.write<int>(errorType);
		writer.write<int>(errorCode);
		}
		multiplexer->sendPacket(pipeId,packet);
		}
	
	if(errorType!=0)
		{
		/* Throw an exception: */
		handleWriteError(errorType,errorCode);
		}
	}
コード例 #3
0
void IOServiceLibEvent::doWrite(ConnectorChannelContext* ctx)
{
	std::list<mxcore::SharedPtr<mxcore::ByteBuffer> > writtenMsgList;

	try
	{
		ctx->writeMessage(writtenMsgList);
		handleWrite(ctx, writtenMsgList);
	} catch (mxcore::IOException& e)
	{
		handleWriteError(ctx, writtenMsgList.front(), e.getErrorCode());
	}
}
コード例 #4
0
	AudioCallDevice::AudioCallDevice (int32_t callIdx, CallManager *manager)
	: Idx_ { callIdx }
	, Manager_ { manager }
	, DataWriter_ { std::make_unique<CallDataWriter> (callIdx, manager) }
	{
		connect (Manager_,
				SIGNAL (gotFrame (int32_t, QByteArray)),
				this,
				SLOT (handleGotFrame (int32_t, QByteArray)));
		connect (DataWriter_.get (),
				SIGNAL (gotError (QString)),
				this,
				SLOT (handleWriteError (QString)));
	}
コード例 #5
0
void TCPPipeSlave::writeData(const IO::File::Byte* buffer,size_t bufferSize)
	{
	/* Receive a status packet from the master: */
	Packet* statusPacket=multiplexer->receivePacket(pipeId);
	Packet::Reader reader(statusPacket);
	int errorType=reader.read<int>();
	int errorCode=reader.read<int>();
	multiplexer->deletePacket(statusPacket);
	
	if(errorType!=0)
		{
		/* Throw an exception: */
		handleWriteError(errorType,errorCode);
		}
	}
コード例 #6
0
ファイル: connection.cpp プロジェクト: tryller/otserv
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
  #ifdef __DEBUG_NET_DETAIL__
	std::clog << "onWriteOperation" << std::endl;
  #endif

	msg.reset();

	m_connectionLock.lock();

	if(!error)
	{
		if(m_pendingWrite > 0)
		{
			if(!m_outputQueue.empty())
			{
				OutputMessage_ptr msg = m_outputQueue.front();
				m_outputQueue.pop_front();
				internalSend(msg);
			  #ifdef __DEBUG_NET_DETAIL__
				std::clog << "Connection::onWriteOperation send " << msg->getMessageLength() << std::endl;
			  #endif
			}
			
			m_pendingWrite--;
		}
		else
		{
			std::clog << "Error: [Connection::onWriteOperation] Getting unexpected notification!" << std::endl;
			// Error. Pending operations counter is 0, but we are getting a
			// notification!!
		}
	}
	else
	{
        m_pendingWrite--;
		handleWriteError(error);
	}

	if(m_closeState == CLOSE_STATE_CLOSING)
	{
		if(!closingConnection())
			m_connectionLock.lock();
		return;
	}

	m_connectionLock.unlock();
}
コード例 #7
0
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
	std::lock_guard<std::recursive_mutex> lockClass(m_connectionLock);;
	m_writeTimer.cancel();

	msg.reset();

	if (error) {
		handleWriteError(error);
	}

	if (m_connectionState != CONNECTION_STATE_OPEN || m_writeError) {
		closeSocket();
		close();
		return;
	}

	--m_pendingWrite;
}
コード例 #8
0
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
	m_connectionLock.lock();
	m_writeTimer.cancel();

	msg.reset();

	if (error) {
		handleWriteError(error);
	}

	if (m_connectionState != CONNECTION_STATE_OPEN || m_writeError) {
		closeSocket();
		closeConnection();
		m_connectionLock.unlock();
		return;
	}

	--m_pendingWrite;
	m_connectionLock.unlock();
}
コード例 #9
0
ファイル: connection.cpp プロジェクト: novasdream/tyano-core
void Connection::onWrite(OutputMessage_ptr msg, const boost::system::error_code& error) {
	LOGt("Connection::onWrite()");

	boost::recursive_mutex::scoped_lock lock(m_connectionLock);

	m_writeTimer.cancel();

	TRACK_MESSAGE(msg);
	msg.reset();
	if(error)
		handleWriteError(error);

	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError)
	{
		closeSocket();
		close();

		return;
	}

	--m_pendingWrite;
}
コード例 #10
0
int BufferManager::write(TCPSocket &sock)
{
    const unsigned int reqlen = (unsigned int)m_lIovList.size();
    struct iovec outdata[reqlen];
    
    memset(outdata,0,reqlen * sizeof(struct iovec));
    
    std::list<iov_req>::iterator aIt,pIt;
    aIt = m_lIovList.begin();
    unsigned int num = 0;
    
    while( aIt != m_lIovList.end())
    {
        outdata[num].iov_base = aIt->m_Iov.iov_base;
        outdata[num].iov_len = aIt->m_Iov.iov_len;
        ++num;
        ++aIt;
    }
    
    int ret = -1;
    while((ret = sock.writevSocket(outdata,reqlen)) < 0)
    {
        if(errno == EINTR)
            continue;
        if( (errno != EWOULDBLOCK) || (errno != EAGAIN))
        {
            handleWriteError();
            return FAILED;
        }
    }
    
    int download = ret;
    #ifdef DEBUG
    std::cout << "send data length:"<< ret << std::endl;
    #endif
    aIt = m_lIovList.begin();
    while(ret > 0 && aIt != m_lIovList.end())
    {
        pIt = aIt++;
        if((unsigned int) ret >= pIt->m_Iov.iov_len)
        {
            ret -= pIt->m_Iov.iov_len;
            if(pIt->m_bComplete)
            {
                if(pIt->m_Iov.iov_base)
                {
                    delete [](char *)(pIt->m_Iov.iov_base);
                    pIt->m_Iov.iov_base = NULL;
                }
            } else {
                if(m_pLastIov)
                {
                    delete [](char *)m_pLastIov;
                    m_pLastIov = NULL;
                }
            } 
            
            if(pIt->m_pTask)
            {
                pIt->m_pTask->writeBack(true);
            } else 
            {
                if(m_pAgent)
                {
                    m_pAgent->writeBack(true);
                } else {
                    handleError("the BufferManager don't relate with a Agent");
                    return FAILED;
                }
            }
            m_lIovList.erase(pIt);
        } else 
        {
            if(pIt->m_bComplete)
            {
                m_pLastIov = pIt->m_Iov.iov_base;
                pIt->m_bComplete = false;
            }
            pIt->m_Iov.iov_base = (void *)(((char *)pIt->m_Iov.iov_base + ret));
            pIt->m_Iov.iov_len -= (unsigned int)ret;
            break;
        }
    }
    
    return download;
}
コード例 #11
0
void IOServiceLibEvent::doWriteTimeout(ConnectorChannelContext* ctx)
{
	ChannelMessage msg = ctx->popFrontWriteMessage();

	handleWriteError(ctx, msg.getBuffer(), IOApplication::ERR_TIMEOUT);
}