示例#1
0
UDPTransmit::UDPTransmit(const IPV6Address &ia, tpport_t port) :   
UDPSocket(ia, port)
{
        disconnect();   // assure not started live
        shutdown(so, 0);
	receiveBuffer(0);
}
示例#2
0
文件: udp.cpp 项目: aberaud/ucommon
UDPTransmit::UDPTransmit(const ucommon::Socket::address &ia) :
UDPSocket(ia)
{
    disconnect();   // assure not started live
    ::shutdown(so, 0);
    receiveBuffer(0);
}
void loop() {
    receiveBuffer();
    transmitBuffer();

    struct timeval end;
    long mtime, seconds, useconds;

    gettimeofday(&end, NULL);
    seconds  = end.tv_sec  - startLoop.tv_sec;
    useconds = end.tv_usec - startLoop.tv_usec;
    mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;

    if( (!serial.isBusySending()) && mtime>10)
    {
        gettimeofday(&startLoop, NULL);

        send_buffer.push(1);
        for(int i=0;i<SEND_BUFFER_SIZE-1;i++){
            send_buffer.push(2);
        }
        serial.sendSerialPacket( &send_buffer );
        uiTxPacketCtr++;
    }
    seconds  = end.tv_sec  - start.tv_sec;
    useconds = end.tv_usec - start.tv_usec;
    mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
    if(mtime > RUNTIME_MS){
        printf("%d packets received\n%d packets sent\nRX data rate = %dbytes/s\nTX data rate = %dbytes/s\n",
               uiRxPacketCtr, uiTxPacketCtr,
               uiRxPacketCtr*(SEND_BUFFER_SIZE-1)*1000/RUNTIME_MS,
               uiTxPacketCtr*(SEND_BUFFER_SIZE-1)*1000/RUNTIME_MS);
        exit(0);
    }
}
示例#4
0
Socket::Error Socket::bufferSize(unsigned bufsize)
{
    Error err = receiveBuffer(bufsize);
    if(err == errSuccess)
        err = sendBuffer(bufsize);

    return err;
}
 void reduceAll(Real* input, Real* output,
                const Elementwise::ReductionOp<Real> &r) {
   int nB = this->numBatches();
   std::vector<Real> receiveBuffer(nB);
   Teuchos::gather<Ordinal,Real>(input,1,&receiveBuffer[0],1,0,*comm_);
   output[0] = r.initialValue();
   for (int i = 0; i < nB; i++) {
     r.reduce(receiveBuffer[i],output[0]);
   }
   Teuchos::broadcast<Ordinal,Real>(*comm_,0,1,output);
 }
/**************************************************************************************
 * Abwicklung eines neuen Clients
 *   - dynamische Erstellung der benutzten Datenstrukturen
 *   1 Anfrage vom Client erhalten (HEADER)
 *   2 Parameter extrahieren
 *   3 Neuen Socket erstellen
 *   4 Neue Adresse Richtung ausgesuchter IP erstellen
 *   5 Verbindung zu IP herstellen
 *   7 Empfangenen HEADER an IP schicken
 *   8 Antwort von IP empfangen
 *   9 Antwort an Client schicken
 */
void* handleClient(void* pTP){
  #ifdef _DEBUG
  fprintf(stderr,"++ handleclient\n");
  #endif
/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^
  int     sProxyWeb   = ~0;
  struct  sockaddr_in saProxyAddress;
  struct  threadParam *pThreadParam=(struct threadParam*)pTP;

  /* Dynamische Bereitstellung des benötigten Speichers */
  struct  urlPar    *pUrlPar     = (struct urlPar*)   malloc(sizeof(struct urlPar));
  struct  netStream *pWebBuf     = (struct netStream*)malloc(sizeof(struct netStream));
  struct  netStream *pClientBuf  = (struct netStream*)malloc(sizeof(struct netStream));
  struct  netStream *pErrBuf     = (struct netStream*)malloc(sizeof(struct netStream));
/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^

  if (receiveHeader      (pClientBuf             ,pThreadParam->socketID))
  if (fillParFromBuf     (pUrlPar                ,pClientBuf->pBuf))
  if (createSocket       (&sProxyWeb))
  if (generateWebAddress (&saProxyAddress        ,pUrlPar))
  if (connectSocket      (sProxyWeb              ,&saProxyAddress))
  if (sendBuffer         (sProxyWeb              ,pClientBuf))
  if (receiveBuffer      (pWebBuf                ,sProxyWeb))
  if (sendBuffer         (pThreadParam->socketID ,pWebBuf));

#ifdef _DEBUG
  fprintf(stderr,"HC - END\n");
#endif

  close(pThreadParam->socketID);
  close(sProxyWeb);
  free(pClientBuf->pBuf);
  free(pClientBuf);
  free(pThreadParam);
  free(pWebBuf->pBuf);
  free(pWebBuf);
  free(pUrlPar);

  #ifdef _DEBUG
  fprintf(stderr,"-- handleclient\n");
  #endif
  //return NULL;
}
示例#7
0
bool receiveBufferWithTimeout(sf::TcpSocket * socket, Buffer * toFill, int max, int timeout)
{
    toFill->size = 0;
    sf::Clock timer;
    while(timer.getElapsedTime().asMilliseconds() < timeout)
    {
        if(receiveBuffer(socket,toFill,max))
        {
            return true;
        }
        
        if(toFill->size > 0)
        {
            break;
        }
        
        sf::sleep(sf::milliseconds(10));
    }
    return false;
}
示例#8
0
void checkForInputs(CheckDataSet data)
{
    Buffer workExchangeBuffer; // use a copy to keep the size
    workExchangeBuffer.pointer = data.exchangeBuffer->pointer;
    
    while(1)
    {
        data.container->containerMutex->lock();
        data.container->selector->wait(sf::milliseconds(100)); // waits for data, 100ms timeout (give a chance to unlock other threads)
        for(int i = 0 ; i < data.container->list->getSize() ; i++)
        {
            if(data.container->list->get(i)->isReady && 
               data.container->selector->isReady(*data.container->list->get(i)->socket))
            {
                if(receiveBuffer(data.container->list->get(i)->socket,&workExchangeBuffer,data.exchangeBuffer->size))
                {
                    logger.printLog("Client disconnected !");
                    killClient(data.container,i);
                }
                if(workExchangeBuffer.size > 0)
                {
                    logger.printDebug("Got data, dispatching");
                    dispatchMessage(data.container,&workExchangeBuffer,i);                
                }
            }
        }
        data.container->containerMutex->unlock();

        if(checkStopThreads())
        {
            return;
        }
        sf::sleep(sf::milliseconds(1)); // give time for the other threads
        
    }    
}
示例#9
0
void
newsoul::TicketSocket::findTicket() {
    if(receiveBuffer().count() < 4)
        return;

    NNLOG("newsoul.ticket.debug", "TicketSocket got %u bytes", receiveBuffer().count());
    // Unpack the ticket
    if (receiveBuffer().count() >= 4 ) {
        unsigned char * data = receiveBuffer().data();
        m_Ticket = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);
        receiveBuffer().seek(4);
    }

    // Notify our waiting downloadsockets
    NNLOG("newsoul.ticket.debug", "Yay! We received ticket %u.. Now what..", m_Ticket);
    newsoul()->downloads()->transferTicketReceivedEvent(this);
    newsoul()->uploads()->transferTicketReceivedEvent(this);

    // Self-terminate
    receiveBuffer().clear();
    newsoul()->reactor()->remove(this);
}
示例#10
0
UDPTransmit::UDPTransmit(Family family) : UDPSocket(family)
{
	disconnect();
	shutdown(so, 0);
	receiveBuffer(0);
}
示例#11
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
	printf("3DS Controller Server %s\n", VERSION);
	
	DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
	DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);
	
	double widthMultiplier = screenWidth / 320.0;
	double heightMultiplier = screenHeight / 240.0;
	
	if(!readSettings()) {
		printf("Couldn't read settings file, using default key bindings.\n");
	}
	
	bool vJoy = true;
	UINT iInterface = settings.vJoyDevice;
	
	iReport.wAxisX = JOY_MIDDLE;
	iReport.wAxisY = JOY_MIDDLE;
	iReport.wAxisZ = JOY_MIDDLE;
	iReport.wAxisXRot = JOY_MIDDLE;
	iReport.wAxisYRot = JOY_MIDDLE;
	iReport.wAxisZRot = JOY_MIDDLE;
	iReport.wSlider = JOY_MIDDLE;
	iReport.wDial = JOY_MIDDLE;
	iReport.lButtons = 0;
	iReport.bHats = -1;
	
	if(vJoy && !vJoyEnabled()) {
		printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n");
		vJoy = false;
	}
	
	enum VjdStat status = GetVJDStatus(iInterface);
	if(vJoy && (status == VJD_STAT_OWN || (status == VJD_STAT_FREE && !AcquireVJD(iInterface)))) {
		printf("vJoy failed (2)! Buttons will still work, but joy stick won't work.\n");
		vJoy = false;
	}
	
	ContPovNumber = GetVJDContPovNumber(iInterface);
	//int DiscPovNumber = GetVJDDiscPovNumber(iInterface);
	
	if((settings.dPad == pov) && !(ContPovNumber == 0)) settings.dPad = cPov;
	
	if(vJoy && !updateJoystick(iInterface)) {
		printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\nIs vJoy device %d configured?\n",iInterface);
		vJoy = false;
	} else printf("Connected to vJoy device %d\n",iInterface);
	
	initNetwork();
	
	char nButtons = GetVJDButtonNumber(iInterface);
	if(vJoy && nButtons <16) printf("Your vJoy has %d buttons, 3DSController supports 16!\n", nButtons);
	
	printf("Port: %d\n", settings.port);
	
	printf("Running on: %s\n", hostName);
	
	printf("Your local IP(s):\n");
	printIPs();
	
	printf("\n");
	
	startListening();
	
	while(1) {
		memset(&buffer, 0, sizeof(struct packet));
		
		while(receiveBuffer(sizeof(struct packet)) <= 0) {
			// Waiting
			
			Sleep(settings.throttle);
		}
		
		keyboardActive = buffer.keyboardActive;
		
		switch(buffer.command) {
			case CONNECT:
				lastKeys = 0;
				currentKeys = 0;
				circlePad.x = 0;
				circlePad.y = 0;
				lastTouch.x = 0;
				lastTouch.y = 0;
				currentTouch.x = 0;
				currentTouch.y = 0;
				cStick.x = 0;
				cStick.y = 0;
				
				buffer.command = CONNECT;
				printf("3DS Connected!\n");
				
				Sleep(50);
				sendBuffer(1);
				
				Sleep(50);
				sendBuffer(1);
				
				Sleep(50);
				sendBuffer(1);
				break;
			
			case KEYS:
				lastKeys = currentKeys;
				if(currentKeys & KEY_TOUCH) lastTouch = currentTouch;
				
				memcpy(&currentKeys, &buffer.keys, 4);
				memcpy(&circlePad, &buffer.circlePad, 4);
				memcpy(&currentTouch, &buffer.touch, 4);
				memcpy(&cStick, &buffer.cStick, 4);
				memcpy(&volume, &buffer.volume, 4);
				//printf("\rVolume is currently: %x ", volume); //test
				
				handleKey(KEY_A, settings.A);
				handleKey(KEY_B, settings.B);
				handleKey(KEY_SELECT, settings.Select);
				handleKey(KEY_START, settings.Start);
				if(settings.dPad == key) { //Handle normally if not using POV in settings.
					handleKey(KEY_DRIGHT, settings.Right);
					handleKey(KEY_DLEFT, settings.Left);
					handleKey(KEY_DUP, settings.Up);
					handleKey(KEY_DDOWN, settings.Down);
				}
				handleKey(KEY_R, settings.R);
				handleKey(KEY_L, settings.L);
				handleKey(KEY_ZR, settings.ZR);
				handleKey(KEY_ZL, settings.ZL);
				handleKey(KEY_X, settings.X);
				handleKey(KEY_Y, settings.Y);
				
				if(settings.circlePad == keys) {
					handleKey(KEY_CPAD_RIGHT, settings.PadRight);
					handleKey(KEY_CPAD_LEFT, settings.PadLeft);
					handleKey(KEY_CPAD_UP, settings.PadUp);
					handleKey(KEY_CPAD_DOWN, settings.PadDown);
				}
				
				if(settings.cStick == keys) {
					handleKey(KEY_CSTICK_RIGHT, settings.CSRight);
					handleKey(KEY_CSTICK_LEFT, settings.CSLeft);
					handleKey(KEY_CSTICK_UP, settings.CSUp);
					handleKey(KEY_CSTICK_DOWN, settings.CSDown);
				}
				
				//handleKey(KEY_LID, 'I');
				
				if(newpress(KEY_TOUCH)) {
					lastTouch.x = currentTouch.x;
					lastTouch.y = currentTouch.y;
				}
				
				if((currentKeys & KEY_TOUCH)) {
					if(keyboardActive) {
						if(newpress(KEY_TOUCH)) {
							char letter = currentKeyboardKey();
							if(letter) {
								simulateKeyNewpress(letter);
								simulateKeyRelease(letter);
							}
						}
					}
					else if(settings.touch == mouse) {
						if(settings.mouseSpeed) {
							POINT p;
							GetCursorPos(&p);
							SetCursorPos(p.x + (currentTouch.x - lastTouch.x) * settings.mouseSpeed, p.y + (currentTouch.y - lastTouch.y) * settings.mouseSpeed);
						}
						else {
							SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier));
						}
					}
					else if(settings.touch == joystick1) { //made a little bit more accurate to the screen size.
						joyX = (int)((float)(currentTouch.x) * 102.3f);
						joyY = (int)((float)(currentTouch.y) * 136.5f);
					}
					
					else if(settings.touch == joystick2) {
						joyRX = (int)((float)(currentTouch.x) * 102.3f);
						joyRY = (int)((float)(currentTouch.y) * 136.5f);
					}
					else {
						handleKey(KEY_TOUCH, settings.Tap);
					}
				} else { //If we are not touching, move to center (Like if you release the joystick on a normal controller).
					if(settings.touch == joystick1) {
						joyX = 16383; //Halfway between the x
						joyY = 16383; //Halfway between the y
					}
					
					else if(settings.touch == joystick2) {
						joyRX = 16383; //Halfway between the rx
						joyRY = 16383; //Halfway between the ry
					}
				}
				
				if(settings.circlePad == mouse) {
					if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0;
					if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0;
					
					POINT p;
					GetCursorPos(&p);
					SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
				}
				else if(settings.circlePad == joystick1) {
					joyX = (circlePad.x + 128) * 128;
					joyY = (128 - circlePad.y) * 128;
				}
				
				else if(settings.circlePad == joystick2) {
					joyRX = (circlePad.x + 128) * 128;
					joyRY = (128 - circlePad.y) * 128;
				}
				
				if(settings.cStick == mouse) {
					if(abs(cStick.x) < settings.mouseSpeed * 3) cStick.x = 0;
					if(abs(cStick.y) < settings.mouseSpeed * 3) cStick.y = 0;
					
					POINT p;
					GetCursorPos(&p);
					SetCursorPos(p.x + (cStick.x * settings.mouseSpeed) / 32, p.y - (cStick.y * settings.mouseSpeed) / 32);
				}
				
				else if(settings.cStick == joystick1) {
					joyX = (cStick.x + 128) * 128;
					joyY = (128 - cStick.y) * 128;
				}
				
				else if(settings.cStick == joystick2) {
					joyRX = (cStick.x + 128) * 128;
					joyRY = (128 - cStick.y) * 128;
				}
				
				
				if(settings.dPad == cPov) {
					if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) {
						if((currentKeys & KEY_DRIGHT)) {
							povHat = 4500;
						} else {
							povHat = 0;
						}
					} else if((currentKeys & KEY_DRIGHT)) {
						if((currentKeys & KEY_DDOWN)) {
							povHat = 13500;
						} else {
							povHat = 9000;
						}
					} else if((currentKeys & KEY_DDOWN)) {
						if((currentKeys & KEY_DLEFT)) {
							povHat = 22500;
						} else {
							povHat = 18000;
						}
					} else if((currentKeys & KEY_DLEFT)) {
						if ((currentKeys & KEY_DUP)) {
							povHat = 31500;
						} else {
							povHat = 27000;
						}
					}
					
					if(!((currentKeys & KEY_DUP) || (currentKeys & KEY_DRIGHT) || (currentKeys & KEY_DDOWN) || (currentKeys & KEY_DLEFT))) {
						//If none are pressed, reset the POV hat
						povHat = -1;
					}
					
				}
				
				else if(settings.dPad == pov) {
					if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) iReport.bHats = 0;
					else if(currentKeys & KEY_DRIGHT) iReport.bHats = 1;
					else if (currentKeys & KEY_DDOWN) iReport.bHats = 2;
					else if (currentKeys & KEY_DLEFT) iReport.bHats = 3;
					else iReport.bHats = -1;
				}
				
				joyVolume = volume * 512;
				
				break;
		}
		
		if(vJoy) updateJoystick(iInterface);
	}
	
	error("accept()");
	return 0;
}
示例#12
0
void
newsoul::HandshakeSocket::onMessageReceived(const MessageData * data)
{
  switch(data->type)
  {
    case 0:
    {
      // Apparently, we requested somebody to connect to us.
      NNLOG("newsoul.messages.handshake", "Received peer handshake message HPierceFirewall");
      HPierceFirewall msg;
      msg.parse_network_packet(data->data, data->length);
      m_Token = msg.token;
      receiveBuffer().seek(data->length + 5);
      // Tell the peer manager, it should know more.
      m_Newsoul->peers()->firewallPiercedEvent(this);
      // This particular socket is no longer needed. Remove it from the reactor.
      reactor()->remove(this);
      return;
    }
    case 1:
    {
      // Somebody wants to establish a connection.
      NNLOG("newsoul.messages.handshake", "Received peer handshake message HInitiate");
      HInitiate msg;
      msg.parse_network_packet(data->data, data->length);
      NNLOG("newsoul.hand.debug", "HInitiate payload: %s %s %u", msg.user.c_str(), msg.type.c_str(), msg.token);
      // Set some variables.
      m_Token = msg.token;
      m_User = msg.user;
      // Seek past the message.
      if (receiveBuffer().count() >= data->length + 5)
        receiveBuffer().seek(data->length + 5);
      else
        receiveBuffer().clear();
      if(msg.type == "P")
      {
        // Create a new PeerSocket which will copy our descriptor and state.
        newsoul::PeerSocket * that = new newsoul::PeerSocket(this);
        newsoul()->peers()->addPeerSocket(that);
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
      }
      else if(msg.type == "F")
      {
        // Create a new TicketSocket which will copy our descriptor and state.
        newsoul::TicketSocket * that = new newsoul::TicketSocket(this);
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
        // There may be some data waiting in the buffer (sent at connection). We have to ask the ticketsocket to check it.
        that->findTicket();
      }
      else if(msg.type == "D")
      {
        // Create a new DistributedSocket which will copy our descriptor and state.
        newsoul::DistributedSocket * that = new newsoul::DistributedSocket(this);
        // A potential parent doesn't care about our position
        if (!newsoul()->searches()->isPotentialParent(m_User))
            that->sendPosition();
        // Add the newly constructed socket to the reactor.
        reactor()->add(that);
      }
      else
      {
        NNLOG("newsoul.hand.warn", "Invalid incoming connection type '%s'.", msg.type.c_str());
      }
      // Clear our receive buffer so we stop processing data.
      receiveBuffer().clear();
      // Remove this socket from the reactor as it's no longer needed.
      reactor()->remove(this);
      return;
    }
    default:
        NNLOG("newsoul.hand.warn", "Received unknown peer handshake message, type: %u, length: %u", data->type, data->length);
        NetworkMessage msg;
        msg.parse_network_packet(data->data, data->length);
  }
}
示例#13
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
    printf("3DS Controller Server %.1f\n", VERSION);

    DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
    DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);

    double widthMultiplier = screenWidth / 320.0;
    double heightMultiplier = screenHeight / 240.0;

    //screenshot(SCREENSHOT_NAMEL, TRUE, 0, 0, 18);

    bool vJoy = true;
    UINT iInterface = 1;

    iReport.wAxisZ = JOY_MIDDLE;
    iReport.wAxisXRot = JOY_MIDDLE;
    iReport.wAxisYRot = JOY_MIDDLE;
    iReport.wAxisZRot = JOY_MIDDLE;
    iReport.wSlider = JOY_MIDDLE;
    iReport.lButtons = 0;
    iReport.bHats = -1;

    if(vJoy && !vJoyEnabled()) {
        printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n");
        vJoy = false;
    }

    enum VjdStat status = GetVJDStatus(iInterface);
    if(vJoy && (status == VJD_STAT_OWN || (status == VJD_STAT_FREE && !AcquireVJD(iInterface)))) {
        printf("vJoy failed (2)! Buttons will still work, but joy stick won't work.\n");
        vJoy = false;
    }

    ContPovNumber = GetVJDContPovNumber(iInterface);
    //int DiscPovNumber = GetVJDDiscPovNumber(iInterface);

    if(vJoy && !updateJoystick()) {
        printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\n");
        vJoy = false;
    }

    if(!readSettings()) {
        printf("Couldn't read settings file, using default key bindings.\n");
    }

    initNetwork();

    printf("Port: %d\n", settings.port);

    printf("Running on: %s\n", hostName);

    printf("Your local IP(s):\n");
    printIPs();

    printf("\n");

    startListening();

    while(1) {
        memset(&buffer, 0, sizeof(struct packet));

        while(receiveBuffer(sizeof(struct packet)) <= 0) {
            // Waiting

            Sleep(settings.throttle);
        }

        keyboardActive = buffer.keyboardActive;

        switch(buffer.command) {
        case CONNECT:
            lastKeys = 0;
            currentKeys = 0;
            circlePad.x = 0;
            circlePad.y = 0;
            lastTouch.x = 0;
            lastTouch.y = 0;
            currentTouch.x = 0;
            currentTouch.y = 0;

            buffer.command = CONNECT;
            printf("3DS Connected!\n");

            Sleep(50);
            sendBuffer(1);

            Sleep(50);
            sendBuffer(1);

            Sleep(50);
            sendBuffer(1);
            break;

        case KEYS:
            lastKeys = currentKeys;
            if(currentKeys & KEY_TOUCH) lastTouch = currentTouch;

            memcpy(&currentKeys, &buffer.keys, 4);
            memcpy(&circlePad, &buffer.circlePad, 4);
            memcpy(&currentTouch, &buffer.touch, 4);

            handleKey(KEY_A, settings.A);
            handleKey(KEY_B, settings.B);
            handleKey(KEY_SELECT, settings.Select);
            handleKey(KEY_START, settings.Start);
            handleKey(KEY_DRIGHT, settings.Right);
            handleKey(KEY_DLEFT, settings.Left);
            handleKey(KEY_DUP, settings.Up);
            handleKey(KEY_DDOWN, settings.Down);
            handleKey(KEY_R, settings.R);
            handleKey(KEY_L, settings.L);
            handleKey(KEY_X, settings.X);
            handleKey(KEY_Y, settings.Y);

            //handleKey(KEY_LID, 'I');

            if(newpress(KEY_TOUCH)) {
                lastTouch.x = currentTouch.x;
                lastTouch.y = currentTouch.y;
            }

            if((currentKeys & KEY_TOUCH)) {
                if(keyboardActive) {
                    if(newpress(KEY_TOUCH)) {
                        char letter = currentKeyboardKey();
                        if(letter) {
                            simulateKeyNewpress(letter);
                            simulateKeyRelease(letter);
                        }
                    }
                }
                else if(settings.touch == mouse) {
                    if(settings.mouseSpeed) {
                        POINT p;
                        GetCursorPos(&p);
                        SetCursorPos(p.x + (currentTouch.x - lastTouch.x) * settings.mouseSpeed, p.y + (currentTouch.y - lastTouch.y) * settings.mouseSpeed);
                    }
                    else {
                        SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier));
                    }
                }
                else if(settings.touch == joystick) {
                    joyX = (currentTouch.x) * 128;
                    joyY = (currentTouch.y) * 128;
                }
                else {
                    handleKey(KEY_TOUCH, settings.Tap);
                }
            }

            if(settings.circlePad == mouse) {
                if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0;
                if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0;

                POINT p;
                GetCursorPos(&p);
                SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
            }
            else if(settings.circlePad == joystick) {
                joyX = (circlePad.x + 128) * 128;
                joyY = (128 - circlePad.y) * 128;
            }

            break;
        }

        if(vJoy) updateJoystick();

        //sendScreenshot();
    }

    error("accept()");
    return 0;
}