/**
 * Trying to read from stream. When location is not available it tries to mount it.
 * @param aBuf buffer to put read data
 * @param aCount length of aBuf
 * @param aCountRead number of bytes actually read
 */
NS_IMETHODIMP
nsGIOInputStream::Read(char     *aBuf,
                       uint32_t  aCount,
                       uint32_t *aCountRead)
{
  *aCountRead = 0;
  // Check if file is already opened, otherwise open it
  if (!mStream && !mDirOpen && mStatus == NS_OK) {
    mStatus = DoOpen();
    if (NS_FAILED(mStatus)) {
      return mStatus;
    }
  }

  mStatus = DoRead(aBuf, aCount, aCountRead);
  // Check if all data has been read
  if (mStatus == NS_BASE_STREAM_CLOSED)
    return NS_OK;

  // Check whenever any error appears while reading
  return mStatus;
}
void Block() {
  Scan();
  NewLine();
  while(Token != 'e' && Token != 'l') {
    switch(Token) {
      case 'i':
        DoIf();
        break;
      case 'w':
        DoWhile();
        break;
      case 'W':
        DoWrite();
        break;
      case 'R':
        DoRead();
        break;
      default:
        Assignment();
    }
    NewLine();
    Scan();
  }
}
void
CachePushStreamChild::Start()
{
  DoRead();
}
Beispiel #4
0
RheiaStringStringMap RheiaConfigurationManager::ReadStringStringMap(const wxString& path)
{
    RheiaStringStringMap ret;
    DoRead(path, &ret);
    return ret;
}
Beispiel #5
0
std::vector<std::string> RheiaConfigurationManager::ReadStdArrayString(const wxString& path)
{
    std::vector<std::string> as;
    DoRead(path, &as);
    return as;
}
Beispiel #6
0
std::vector<int> RheiaConfigurationManager::ReadStdArrayInt(const wxString& path)
{
    std::vector<int> ai;
    DoRead(path, &ai);
    return ai;
}
Beispiel #7
0
std::vector<double> RheiaConfigurationManager::ReadStdArrayDouble(const wxString& path)
{
    std::vector<double> ad;
    DoRead(path, &ad);
    return ad;
}
Beispiel #8
0
	void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
	{

		MemoServ::MemoInfo *mi;
		ChanServ::Channel *ci = NULL;
		Anope::string numstr = params[0], chan;

		if (!numstr.empty() && numstr[0] == '#')
		{
			chan = numstr;
			numstr = params.size() > 1 ? params[1] : "";

			ci = ChanServ::Find(chan);
			if (!ci)
			{
				source.Reply(_("Channel \002{0}\002 isn't registered."), chan);
				return;
			}

			if (!source.AccessFor(ci).HasPriv("MEMO"))
			{
				source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "MEMO", ci->GetName());
				return;
			}

			mi = ci->GetMemos();
		}
		else
			mi = source.nc->GetMemos();

		if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && !numstr.is_number_only()))
		{
			this->OnSyntaxError(source, numstr);
			return;
		}

		if (!mi)
			return;

		auto memos = mi->GetMemos();

		if (memos.empty())
		{
			if (!chan.empty())
				source.Reply(_("\002{0}\002 has no memos."), chan);
			else
				source.Reply(_("You have no memos."));
			return;
		}

		int i, end;

		if (numstr.equals_ci("NEW"))
		{
			int readcount = 0;
			for (i = 0, end = memos.size(); i < end; ++i)
				if (mi->GetMemo(i)->GetUnread())
				{
					DoRead(source, mi, ci, i);
					++readcount;
				}
			if (!readcount)
			{
				if (!chan.empty())
					source.Reply(_("\002{0}\002 has no new memos."), chan);
				else
					source.Reply(_("You have no new memos."));
			}
		}
		else if (numstr.equals_ci("LAST"))
		{
			for (i = 0, end = memos.size() - 1; i < end; ++i);
			DoRead(source, mi, ci, i);
		}
		else /* number[s] */
		{
			NumberList(numstr, false,
				[&](unsigned int number)
				{
					if (!number || number > memos.size())
						return;

					DoRead(source, mi, ci, number - 1);
				},
				[]{});
		}
	}
Beispiel #9
0
wxArrayDouble RheiaConfigurationManager::ReadArrayDouble(const wxString& path)
{
    wxArrayDouble ad;
    DoRead(path, &ad);
    return ad;
}
Beispiel #10
0
wxArrayInt RheiaConfigurationManager::ReadArrayInt(const wxString& path)
{
    wxArrayInt ai;
    DoRead(path, &ai);
    return ai;
}
Beispiel #11
0
wxArrayString RheiaConfigurationManager::ReadArrayString(const wxString& path)
{
    wxArrayString as;
    DoRead(path, &as);
    return as;
}
Beispiel #12
0
void CActiveReader::RunL()
	{
	// the read has completed - for the moment we are not really interested at the moment

	if (iAuto)
		{
		switch (iReadState)
			{
			case EReadHeader:
				iReaderOutputConsole->Printf(_L("Header byte recvd\n"));
				iReadState = (DecodeHeader() == KHCIUARTCommandHeader ? EReadOpcode : EReadConnectionHandleFlags);
				break;
			case EReadOpcode:
				{
				iReaderOutputConsole->Printf(_L("Opcode bytes recvd\n"));
				TInt opcode = DecodeOpcode();
				if (opcode == 0)
					//NoOpCommand has no more parameters
					{
					iReadComplete = ETrue;
					iReadState = EReadHeader; // start again
					}
				else
					{
					iReadState = EReadCommandLength;
					}
				}
				break;
			case EReadCommandLength:
				iReaderOutputConsole->Printf(_L("Length byte recvd\n"));
				iReadState = EReadCommandRemainder;
				break;
			case EReadDataLength:
				iReaderOutputConsole->Printf(_L("Length byte recvd\n"));
				iReadState = EReadDataRemainder;
				break;
			case EReadConnectionHandleFlags:
				iReaderOutputConsole->Printf(_L("ConnectionHandle bytes recvd\n"));
				iReadState = EReadDataLength;
				break;
			case EReadCommandRemainder:
			case EReadDataRemainder:
				iReaderOutputConsole->Printf(_L("Remainder bytes recvd\n"));
				iReadComplete = ETrue;
				iReadState = EReadHeader; // start again
				break;

			default:
				__DEBUGGER();
			}
		
		if (iReadComplete)
			{
			iReaderOutputConsole->Printf(_L("Decoding...\n"));

			if (DecodeHeader() == KHCIUARTCommandHeader)
				{
				iReaderOutputConsole->Printf(_L("Decode: Command\n"));
				iEmulator.CommandReceived(iOpcodeBuf, iRemainderBuf);
				}
			else
				{
				iReaderOutputConsole->Printf(_L("Decode: ACL Data\n"));
				iEmulator.ACLDataReceived(iConnectionHandleFlagsBuf, iRemainderBuf);
				}
			iReadComplete = EFalse;
			}
				

		}

	// queue another one
	DoRead();
	}
Beispiel #13
0
void Connection::Start(void)
{
	DoRead();
}
Beispiel #14
0
	virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult)
	{
		issl_session* session = &sessions[fd];
		
		if(!session->sess)
		{
			ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: No session to read from");
			readresult = 0;
			CloseSession(session);
			return 1;
		}
		
		ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead(%d, buffer, %u, %d)", fd, count, readresult);
		
		if(session->status == ISSL_HANDSHAKING)
		{
			if(session->rstat == ISSL_READ || session->wstat == ISSL_READ)
			{
				// The handshake isn't finished and it wants to read, try to finish it.
				if(Handshake(session))
				{
					// Handshake successfully resumed.
					ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: successfully resumed handshake");
				}
				else
				{
					// Couldn't resume handshake.	
					ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: failed to resume handshake");
					return -1;
				}
			}
			else
			{
				ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: handshake wants to write data but we are currently reading");
				return -1;			
			}
		}
		
		// If we resumed the handshake then session->status will be ISSL_OPEN
				
		if(session->status == ISSL_OPEN)
		{
			if(session->wstat == ISSL_READ)
			{
				if(DoWrite(session) == 0)
					return 0;
			}
			
			if(session->rstat == ISSL_READ)
			{
				int ret = DoRead(session);
			
				if(ret > 0)
				{
					if(count <= session->inbufoffset)
					{
						memcpy(buffer, session->inbuf, count);
						// Move the stuff left in inbuf to the beginning of it
						memcpy(session->inbuf, session->inbuf + count, (session->inbufoffset - count));
						// Now we need to set session->inbufoffset to the amount of data still waiting to be handed to insp.
						session->inbufoffset -= count;
						// Insp uses readresult as the count of how much data there is in buffer, so:
						readresult = count;
					}
					else
					{
						// There's not as much in the inbuf as there is space in the buffer, so just copy the whole thing.
						memcpy(buffer, session->inbuf, session->inbufoffset);
						
						readresult = session->inbufoffset;
						// Zero the offset, as there's nothing there..
						session->inbufoffset = 0;
					}
				
					return 1;
				}
				else
				{
					return ret;
				}
			}
		}
		
		return -1;
	}
//*******************************************************************************
// Method      : CRtpAppConsole::StartTesting()
// Purpose     : start this AO 
// Parameters  : 
// Return Value: 
//*******************************************************************************
void CTestAppConsole::StartTesting()
    {
	DoRead();
    }
Beispiel #16
0
void MainProc() {
	for (;;) {
		int MaxFd;
		fd_set ReadQ;
		fd_set WriteQ;

		if (Reconnect) {
			close(connection->Fd);
			FreeConnection(connection);
			// To prevent floods. I know, this should be rather handled by ewrecv, but that would be nontrivial.
			sleep(2);
			AttachConnection();
			Reconnect = 0;
		}

		MaxFd = 0;

		FD_ZERO(&ReadQ);
		FD_ZERO(&WriteQ);

		// stdin
		if (read_from_stdin
		&& !want_quit
		&& strlen(Commands) < COMMANDS_MAXLEN) {
			FD_SET(0, &ReadQ);
		}

		if (connection) {
			FD_SET(connection->Fd, &ReadQ);
			if (connection->Fd > MaxFd) MaxFd = connection->Fd;
			if (connection->WriteBuffer) FD_SET(connection->Fd, &WriteQ);
		}

		struct timeval to;
		to.tv_sec = timeout_denominator;
		to.tv_usec = 0;
		struct timeval *top = &to;
		if (timeout_denominator == 0) top = NULL;

		int s = select(MaxFd + 1, &ReadQ, &WriteQ, 0, top);

		if (s < 0) {
			if (errno == EINTR) continue;
			Done(1);
		} else if (s == 0) {
			// timeout
		} else {
			// stdin
			if (read_from_stdin
			&& strlen(Commands) < COMMANDS_MAXLEN
			&& FD_ISSET(0, &ReadQ)) {
				char buf[256+1] = "";

				int to_read = COMMANDS_MAXLEN - strlen(Commands);
				if (to_read > 256) to_read = 256;

				int r = read(0, buf, to_read);
				buf[r] = 0;

				if (r == 0) {
					want_quit = 1;

					TryQuit();
				} else {
					strncat(Commands, buf, r);

					SendNextCommand();
				}
			}

			// Exchange input
			if (connection && FD_ISSET(connection->Fd, &ReadQ)) {
				errno = 0;
				if (DoRead(connection) <= 0) {
					if (detaching) {
						Done(0);
					} else {
						Done(1);
					}
				} else {
					int Chr;

					while (Read(connection, &Chr, 1)) {
						TestIProtoChar(connection, Chr);
					}
				}
			}

			// Exchange output
			if (connection && FD_ISSET(connection->Fd, &WriteQ)) {
				if (DoWrite(connection) < 0) Done(1);
			}
		}

		if (login_timeout && login_start && !logged_in) {
			if (time(NULL) - login_start > login_timeout) Done(103);
		}

		if (command_timeout && command_start && jobs) {
			if (time(NULL) - command_start > command_timeout) Done(104);
		}
	}
}
Beispiel #17
0
wxArrayBool RheiaConfigurationManager::ReadArrayBool(const wxString& path)
{
    wxArrayBool ab;
    DoRead(path, &ab);
    return ab;
}
Beispiel #18
0
void dng_stream::Get (void *data, uint32 count)
	{
	
	while (count)
		{
		
		// See if the request is totally inside buffer.
		
		if (fPosition >= fBufferStart && fPosition + count <= fBufferEnd)
			{
			
			DoCopyBytes (fBuffer + (uint32) (fPosition - fBufferStart),
						 data,
						 count);
						 
			fPosition += count;
			
			return;
			
			}
			
		// See if first part of request is inside buffer.
		
		if (fPosition >= fBufferStart && fPosition < fBufferEnd)
			{
			
			uint32 block = (uint32) (fBufferEnd - fPosition);
			
			DoCopyBytes (fBuffer + (fPosition - fBufferStart),
						 data,
						 block);
			
			count -= block;
			
			data = (void *) (((char *) data) + block);
			
			fPosition += block;
			
			}
			
		// Flush buffer if dirty.
		
		Flush ();
		
		// Do large reads unbuffered.
		
		if (count > fBufferSize)
			{
			
			if (fPosition + count > Length ())
				{
				
				ThrowEndOfFile ();
				
				}
				
			DoRead (data,
					count,
					fPosition);
					
			fPosition += count;
			
			return;
			
			}
			
		// Figure out new buffer range.
		
		fBufferStart = fPosition;
		
		if (fBufferSize >= 4096)
			{
			
			// Align to a 4K file block.
			
			fBufferStart &= (uint64) ~((int64) 4095);
			
			}
		
		fBufferEnd = Min_uint64 (fBufferStart + fBufferSize, Length ());
		
		if (fBufferEnd <= fPosition)
			{
			
			ThrowEndOfFile ();

			}
			
		// Read data into buffer.
		
		dng_abort_sniffer::SniffForAbort (fSniffer);
		
		DoRead (fBuffer,
				(uint32) (fBufferEnd - fBufferStart),
				fBufferStart);
		
		}

	}
Beispiel #19
0
std::vector<bool> RheiaConfigurationManager::ReadStdArrayBool(const wxString& path)
{
    std::vector<bool> ab;
    DoRead(path, &ab);
    return ab;
}