コード例 #1
0
ファイル: LSOCKETS.CPP プロジェクト: DimeSPb/ecuExplorer
BOOL CListeningSocket::WaitForConnection( const int port_number )
{
   ASSERT_VALID( this );
   ASSERT( port_number > 0 );

   SetPort( (short) port_number );

   return( WaitForConnection() );
}
コード例 #2
0
ファイル: SocketServer.c プロジェクト: adamblack1/cslim
int SocketServer_Run(SocketServer* self, char * listening_port_number)
{
	self->itsPort = atoi(listening_port_number);
	StartWSA(self);
	CreateSocket(self);
	BindToSocket(self);
	WaitForConnection(self);	
	Shutdown(self);

    return 0;
}
コード例 #3
0
ファイル: LSOCKETS.CPP プロジェクト: DimeSPb/ecuExplorer
BOOL CListeningSocket::WaitForConnection( const char *p_name )
{
   ASSERT_VALID( this );
   ASSERT( p_name != NULL );

   if ( p_name == NULL )
   {
      m_ErrorCode = ERROR_INVALID_PARAMETER;
      return( FALSE );
   }

   SetPort( p_name );

   return( WaitForConnection() );
}
コード例 #4
0
void ModelViewController::SimplePrint()
{
	if( serial->isPrinting() )
	{
		fl_alert ("Already printing.\nCannot start printing");
	}

	if( !serial->isConnected() )
	{
		ConnectToPrinter(true);
		WaitForConnection(5.0);
	}

	Print();
}
コード例 #5
0
ファイル: stalker.c プロジェクト: aaSSfxxx/Stalker
int main (int argc, char** argv) {
	HANDLE hNamedPipe;
	BOOTSTRAP_INFO info;
	DWORD dwRead;
	STARTUPINFOA SI;
    PROCESS_INFORMATION PI;
	SERVICE_PACKET pack;
	int i;
	/* Parsing command line */
	dumpFolder = LocalAlloc(LPTR, 1000);
	// Getting the dump directory
	if(argc < 2) {
		usage(argv);
	}
	info.allowCall = FALSE;
	info.noResume = FALSE;
	GetCurrentDirectory(1000, dumpFolder);
	// Loop for options
	for(i = 1; i < argc-1; i++) {
		if( strcmp(argv[i], "-d") != 0) {
			if( strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--allow-call") == 0) {
				info.allowCall = TRUE;
			}
			else {
				if( strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--block-resume-thread") == 0) {
					info.noResume = TRUE;
				}
				else {
					
					printf("Unrecognized argument %s.\n", argv[i]);
					usage(argv);
				}
			}
		}
		else {
			strncpy(dumpFolder, argv[i + 1], 1000 - 1); // to have a null byte
			i++;
		}
		
	}
	
	
	dwRead = strlen(dumpFolder) - 1;
	if(dumpFolder[dwRead] == '\\') {
		dumpFolder[dwRead] = '\0';
	}
	printf("Dump folder is \"%s\"\n", dumpFolder);
	printf("Creating IPC pipe.\n");
	if( (hNamedPipe = CreateIPCPipe()) == INVALID_HANDLE_VALUE) {
		printf("Couldn't create pipe. Aborting.\n");
		exit(-1);
	}
	printf ("Creating process.\n");
	
	/* Creating the process in the suspended way */
	RtlZeroMemory(&SI, sizeof(SI));
    RtlZeroMemory(&PI, sizeof(PI));
	
	if(!CreateProcess(argv[argc - 1], NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &SI, &PI))
	{
		printf("Unable to create process. Error code 0x%08x\n", (int)GetLastError());
		exit(-1);
	}
	InitializeDLLInjection(PI);
	
	// Fill structure
	strncpy(info.DumpDirectory, dumpFolder, 1000);
	
	if( !WaitForConnection(hNamedPipe) ) {
		exit(-1);
	}
	WriteFile (hNamedPipe, &info, sizeof(info), &dwRead, 0);
	
	BOOL notFinished = TRUE;
	do {
		if(ReadFile(hNamedPipe, &pack , sizeof(SERVICE_PACKET), &dwRead, 0)) {
			if (pack.ServiceCode == CODE_ENDED) {
				printf ("Subprocess exited.\n");
				notFinished = FALSE;
			}
			else {
				printf ("Tried to write %d bytes to address 0x%08x of PID %d\n", (int)pack.Data2, (int)pack.Data1, (int)pack.Data3);
			}
		}
		else {
			printf("Subprocess had a problem.\n");
			notFinished = FALSE;
		}
	} while(notFinished);
	FlushFileBuffers(hNamedPipe);
	DisconnectNamedPipe(hNamedPipe);
	CloseHandle(hNamedPipe);
	return 0;
}
コード例 #6
0
///////////////////////////////////////////////////////////////////////////////
// Run
///////////////////////////////////////////////////////////////////////////////
// DESCRIPTION:
//      This function runs the main thread loop
//      this implementation can be overloaded.
//      This function calls CSocketComm::OnDataReceived() (Virtual Function)
// PARAMETERS:
// NOTES:
//      You should not wait on the thread to end in this function or overloads
///////////////////////////////////////////////////////////////////////////////
void CSocketComm::Run()
{
    stMessageProxy stMsgProxy;
    DWORD   dwBytes  = 0L;
    DWORD   dwTimeout = INFINITE;
    LPBYTE  lpData  = (LPBYTE)&stMsgProxy;
    DWORD   dwSize  = sizeof(stMsgProxy);

    bool bSmartAddressing = IsSmartAddressing();
    if ( !bSmartAddressing )
    {
        lpData = stMsgProxy.byData;
        dwSize = sizeof(stMsgProxy.byData);
    }

    // Should we run as server mode
    if (IsServer() && !bSmartAddressing)
    {
        if (!IsBroadcast())
        {
            SOCKET sock = (SOCKET) m_hComm;
            sock = WaitForConnection( sock );

            // Get new connection socket
            if (sock != INVALID_SOCKET)
            {
                ShutdownConnection( (SOCKET) m_hComm);
                m_hComm = (HANDLE) sock;
                OnEvent( EVT_CONSUCCESS, NULL ); // connect
            }
            else
            {
                // Do not send event if we are closing
                if (IsOpen())
                    OnEvent( EVT_CONFAILURE, NULL ); // wait fail
                return;
            }
        }
    }
    else
    {
        GetPeerName( stMsgProxy.address );
    }

    while( IsOpen() )
    {
        // Blocking mode: Wait for event
        dwBytes = ReadComm(lpData, dwSize, dwTimeout);

        // Error? - need to signal error
        if (dwBytes == (DWORD)-1L)
        {
            // Do not send event if we are closing
            if (IsOpen())
            {
                if ( bSmartAddressing )
                {
                    RemoveFromList( stMsgProxy.address );
                }
                OnEvent( EVT_CONDROP, &stMsgProxy.address ); // lost connection
            }

            // special case for UDP, alert about the event but do not stop
            if ( bSmartAddressing )
                continue;
            else
                break;
        }

        // Chars received?
        if ( bSmartAddressing && dwBytes == sizeof(SOCKADDR_IN))
        {
            OnEvent( EVT_ZEROLENGTH, NULL );
        }
        else if (dwBytes > 0L)
        {
            OnDataReceived( lpData, dwBytes);
        }

        //Sleep(0);
    }
}
コード例 #7
0
ファイル: Serial.cpp プロジェクト: SysMan-One/es40
void CSerial::execute()
{
  fd_set          readset;
  unsigned char   buffer[FIFO_SIZE + 1];
  unsigned char   cbuffer[FIFO_SIZE + 1]; // cooked buffer
  unsigned char*  b;

  // cooked buffer
  unsigned char *c;
  ssize_t         size;
  struct timeval  tv;

  state.serial_cycles++;
  if(state.serial_cycles >= RECV_TICKS)
  {
    FD_ZERO(&readset);
    FD_SET(connectSocket, &readset);
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    if(select(connectSocket + 1, &readset, NULL, NULL, &tv) > 0)
    {
#if defined(_WIN32) || defined(__VMS)

      // Windows Sockets has no direct equivalent of BSD's read
      size = recv(connectSocket, (char*) buffer, FIFO_SIZE, 0);
#else
      size = read(connectSocket, &buffer, FIFO_SIZE);
#endif

      extern int  got_sigint;
      if(size == 0 && !got_sigint)
      {
        printf("%%SRL-W-DISCONNECT: Write socket closed on other end for serial port %d.\n",
             state.iNumber);
        printf("-SRL-I-WAITFOR: Waiting for a new connection on port %d.\n",
               listenPort);
        WaitForConnection();
        return;
      }

      b = buffer;
      c = cbuffer;
      while((ssize_t) (b - buffer) < size)
      {
        if(*b == 0x0a)
        {
          b++;      // skip LF
          continue;
        }

        if(*b == IAC)
        {
          if(*(b + 1) == IAC)
          {         // escaped IAC.
            b++;
          }
          else if(*(b + 1) >= WILL)
          {         // will/won't/do/don't
            b += 3; // skip this byte, and following two. (telnet escape)
            continue;
          }
          else if(*(b + 1) == SB)
          {         // skip until IAC SE
            b += 2; // now we're at start of subnegotiation.
            while(*b != IAC && *(b + 1) != SE)
              b++;
            b += 2;
            continue;
          }
          else if(*(b + 1) == BREAK)
          {         // break (== halt button?)
            b += 2;
            breakHit = true;
          }
          else if(*(b + 1) == AYT)
          {         // are you there?
          }
          else
          {         // misc single byte command.
            b += 2;
            continue;
          }
        }

        *c = *b;
        c++;
        b++;
      }

      this->receive((const char*) &cbuffer, (c - cbuffer));
    }

    state.serial_cycles = 0;
  }

  eval_interrupts();
}
コード例 #8
0
ファイル: Serial.cpp プロジェクト: SysMan-One/es40
/**
 * Initialize the Serial port device.
 **/
void CSerial::init()
{
  listenPort = (int) myCfg->get_num_value("port", false, 8000 + state.iNumber);

  char    s[1000];
  char*   nargv = s;
  int     i = 0;

  cSystem->RegisterMemory(this, 0,
                          U64(0x00000801fc0003f8) - (0x100 * state.iNumber), 8);

  // Start Telnet server
#if defined(_WIN32)

  // Windows Sockets only work after calling WSAStartup.
  WSADATA wsa;
  WSAStartup(0x0101, &wsa);
#endif // defined (_WIN32)
  struct sockaddr_in  Address;

  socklen_t           nAddressSize = sizeof(struct sockaddr_in);

  listenSocket = (int) socket(AF_INET, SOCK_STREAM, 0);
  if(listenSocket == INVALID_SOCKET)
  {
    printf("Could not open socket to listen on!\n");
  }

  Address.sin_addr.s_addr = INADDR_ANY;
  Address.sin_port = htons((u16) (listenPort));
  Address.sin_family = AF_INET;

  int optval = 1;
  setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &optval,
             sizeof(optval));
  bind(listenSocket, (struct sockaddr*) &Address, sizeof(Address));
  listen(listenSocket, 1);

  printf("%s: Waiting for connection on port %d.\n", devid_string, listenPort);

  WaitForConnection();

#if defined(IDB) && defined(LS_MASTER)
  struct sockaddr_in  dest_addr;
  int                 result = -1;

  throughSocket = socket(AF_INET, SOCK_STREAM, 0);

  dest_addr.sin_family = AF_INET;
  dest_addr.sin_port = htons((u16) (base + number));
  dest_addr.sin_addr.s_addr = inet_addr(ls_IP);

  printf("%s: Waiting to initiate remote connection to %s.\n", devid_string,
         ls_IP);

  while(result == -1)
  {
    result = connect(throughSocket, (struct sockaddr*) &dest_addr,
                     sizeof(struct sockaddr));
  }
#endif
  state.rcvW = 0;
  state.rcvR = 0;

  state.bLCR = 0x00;
  state.bLSR = 0x60;  // THRE, TSRE
  state.bMSR = 0x30;  // CTS, DSR
  state.bIIR = 0x01;  // no interrupt
  state.irq_active = false;
  myThread = 0;

  printf("%s: $Id: Serial.cpp,v 1.51 2008/06/03 09:07:56 iamcamiel Exp $\n",
         devid_string);
}