예제 #1
0
bool Socket::readToBuffer()
{
	if(file < 0)
		throw InvalidState("Socket is closed.");

	char buffer[64*1024];
	ssize_t readIn = 0;

	do{
		readIn = 0;
		do {
			readBuffer.append(buffer, readIn);
			if(0 < readIn){
				totalReceived += readIn;
				dataReceived();
				if(file == -1) // closed by child class
					return true;
			}
			readIn = ::read(file, buffer, sizeof(buffer));
		} while(0 < readIn);
	} while(readIn < 0 && errno == EINTR);

	if(readIn < 0 && ( errno != EAGAIN /*&& errno != EWOULDBLOCK*/ ) )
		throw SocketError(errno, "Error while reading from socket.");

	return 0 <= readIn; // false if EAGAIN or EWOULDBLOCK happened
}
예제 #2
0
bool Socket::writeFromBuffer()
{
	if(file < 0)
		throw InvalidState("Socket is closed.");

	long unsigned written = 0;
	int justWritten = 0;
	do {
		justWritten = 0;
		do {
			written += justWritten;
			justWritten = ::write(file,
					writeBuffer.c_str() + written,
					writeBuffer.length - written);
		} while(0 < justWritten);
	} while(justWritten < 0 && errno == EINTR);
	int errNo = errno;

	totalSent += written;
	writeBuffer.chopFront(written);

	if(justWritten < 0 && (errNo == EPIPE || errNo == ECONNRESET))
		throw SocketClosedByPeer(errNo, "Error after writting % bytes "
				"to socket.", written);

	if(justWritten < 0 && ( errNo != EAGAIN /*&& errNo != EWOULDBLOCK*/))
		throw SocketError(errNo, "Error after writting % bytes "
				"to socket.", written);

	if(closeOnSent && writeBuffer.length == 0)
		close();

	return 0 <= justWritten; // false if EAGAIN or EWOULDBLOCK happened
}
예제 #3
0
int InteractionVector<Vector>::getNumberOfIndividualsToInclude() const {
#ifdef DEBUG
  if(!initialised){
    throw InvalidState("InteractionVector is not initialised.");
  }
#endif
  return numberOfIndividualsToInclude;
}
예제 #4
0
Vector& InteractionVector<Vector>::getInteractionData() {
#ifdef DEBUG
  if(!initialised){
    throw InvalidState("InteractionVector is not initialised.");
  }
#endif

  return *interactionExMissing;
}
예제 #5
0
bool Socket::send(const Str & data)
{
	if(file < 0)
		throw InvalidState("Socket is closed.");

	writeBuffer.append(data);

	return writeFromBuffer();
}
예제 #6
0
파일: RpcServer.cpp 프로젝트: pheest/pvaPy
void RpcServer::listen(int seconds)
{
    if (destroyed) {
        throw InvalidState("Invalid state: server has been shutdown and cannot be restarted.");
    }
    printInfo();
    run(seconds);
    destroyed = true;
}
예제 #7
0
파일: RpcServer.cpp 프로젝트: pheest/pvaPy
void RpcServer::startListener()
{
    if (destroyed) {
        throw InvalidState("Invalid state: server has been shutdown and cannot be restarted.");
    }

    // One must call PyEval_InitThreads() in the main thread
    // to initialize thread state, which is needed for proper functioning
    // of PyGILState_Ensure()/PyGILState_Release().
    PyGilManager::evalInitThreads();
    epicsThreadCreate("RpcServerListenerThread", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), (EPICSTHREADFUNC)listenerThread, this);
}
예제 #8
0
파일: SNP.cpp 프로젝트: Berjiz/CuEira
RiskAllele SNP::getRiskAllele() const {
  if(!riskAlleleHasBeenSet){
    std::ostringstream os;
    os << "Can't get risk allele since it has not been set for SNP " << id.getString() << std::endl;
    const std::string& tmp = os.str();
    throw InvalidState(tmp.c_str());
  }

  if(snpIsRisk){
    return riskAllele;
  }else{
    return riskAllele == ALLELE_ONE ? ALLELE_TWO : ALLELE_ONE;
  }
}
예제 #9
0
String Socket::receive(size_t length)
{
	if(file < 0)
		throw InvalidState("Socket is closed.");

	if(readBuffer.length < length){
		readToBuffer();
		if(readBuffer.length < length)
			throw SocketError("Can not yet read % byte long "
					"string from socket.", length);
	}

	String ret(readBuffer.read(0, length));
	readBuffer.chopFront(length);

	return ret;
}