示例#1
0
int main(int argc, char** argv) {
    sf::Window* window = allocateWindow("Test", 800, 450);
	waitForClose(window);
    deallocateWindow(window);
}
示例#2
0
/** used by thread to process new request*/
void * processRequest(void * param) {
  RequestInfo *requestInfo = (RequestInfo *) param;
  int  sockFd = requestInfo->sockFd;
  char *clientIP  = requestInfo->clientIP;
  int  clientPort = requestInfo->clientPort;

  printf("start to serve request from %s:%d\n", clientIP, clientPort);
  //receive request file information
  char requestFile[1024] = {0};
  int recvStatus = recvFromSock(sockFd, requestFile, sizeof requestFile - 1, 1);
  if (recvStatus < 0) {
	printf("recv request info failed\n");
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  } else if (recvStatus == 0) {
	printf("client has closed this connection\n");
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  }
  printf("requestInfo: %s\n", requestFile);

  // check File existence and open file
  if (!checkFileExist(requestFile)) {
	printf("file doesn't exist: %s\n", requestFile);
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  }
  FILE * fd = fopen(requestFile, "r");
  if (!fd) {
	printf("open request file failed\n");
	goto cleanAndQuit;
  }

  // send requested file
  char buffer[1024];
  unsigned int requestFileSize = getFileSize(requestFile);
  unsigned int readSize = 0;
  unsigned int sentSize = 0;
  printf("start to send to client\n");
  while (readSize < requestFileSize) {
	unsigned int tempReadLen = 0;
	memset(buffer, 0, sizeof buffer);
	if ((tempReadLen = fread(buffer, sizeof(char), sizeof buffer -1, fd)) < 0) {
	  printf("read file failed %d\n", tempReadLen);
	  goto cleanAndQuit;
	}
	readSize += tempReadLen;

	//send to socket
    if (sendToSock(sockFd, buffer, tempReadLen, 1) != 1) {
	  printf("send to sock failed\n");
	  goto cleanAndQuit;
	}
	sentSize += tempReadLen;
	//printf("send to client with len %d, sumLen, %d\n", sumSentLen, sentSize);

	if (canRead(sockFd) != 1) {
	  continue;
	}
	printf("start to receive cancel/close msg\n");
	memset(buffer, 0, sizeof buffer);
    int recvLen = recvFromSock(sockFd, buffer, sizeof buffer - 1, 1);
	if (recvLen <= 0) {// the other side has close the sockfd or some error happens
	  printf("failed to recv close/cancel signal\n");
	  goto cleanAndQuit;
	}
	printf("sent %d KB data\n", sentSize / 1024);
	printf("receive cancel/close msg: %s\n", buffer);
	if (strcmp(buffer, CANCEL_MSG) == 0) {
	  printf("wait for close after receiving cancel msg\n");
	  if (waitForClose(sockFd) == 1) {
		printf("client close connection, quit right now\n");
	  } else {
		printf("waitForClose Failed, quit right now\n");
	  }
	} else {
	  printf("close after receiving close msg\n");
	}
	cleanAndQuit:
	closeSock(sockFd);
	if (requestInfo) {
	  free(requestInfo);
	}
	if (fd) {
	  fclose(fd);
	}
	return NULL;
  }
}
示例#3
0
static void *
mainLoop(void *param)
{
    AT_DUMP("== ", "entering mainLoop()", -1 );
    at_set_on_reader_closed(onATReaderClosed);
    at_set_on_timeout(onATTimeout);
    initRILChannels();
	RLOGI("[Emu]mainloop_in");
	RLOGI("[Emu]mainloop_in %d\n",s_device_socket);
	if(s_device_socket)
		{
		emulator_gemini_opensocket();
		return NULL;
	}
	else
		{
		int ret;
	       int i;
	    	RILChannelCtx * p_channel;
	
	    	for (;;) {

		        for (i=0; i < RIL_SUPPORT_CHANNELS; i ++)
		        {
		            p_channel = getChannelCtxbyId(i);

		            while (p_channel->fd < 0)
		            {
		                do {
		                    p_channel->fd = open(s_mux_path[i], O_RDWR);
		                } while (p_channel->fd < 0 && errno == EINTR);
		                
		                if (p_channel->fd < 0) 
		                {
		                    perror ("opening AT interface. retrying...");
		                    RLOGE("could not connect to %s: %s",  s_mux_path[i], strerror(errno));
		                    sleep(10);
		                    /* never returns */
		                }
		                else
		                {
		                    struct termios  ios;
		                    tcgetattr(p_channel->fd, &ios );
		                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
                  			  ios.c_iflag = 0;
		                    tcsetattr(p_channel->fd, TCSANOW, &ios );
		                }
		            }
		            
		            
		            s_closed = 0;
		            ret = at_open(p_channel->fd,onUnsolicited, p_channel);
		            
		            
		            if (ret < 0) {
		                RLOGE ("AT error %d on at_open\n", ret);
		                return 0;
		            }
	      		  }

		        RIL_requestTimedCallback(initializeCallback, &s_pollSimId, &TIMEVAL_0);
#ifdef MTK_GEMINI
		        RIL_requestTimedCallback(initializeCallback, &s_pollSimId2, &TIMEVAL_0);
#endif 

		        // Give initializeCallback a chance to dispatched, since
		        // we don't presently have a cancellation mechanism
		        sleep(1);

		        waitForClose();
		        RLOGI("Re-opening after close");
		}
   	 }
	
}
示例#4
0
static void *
mainLoop(void *param)
{
    int fd;
    int ret;
    char path[50];
    int ttys_index;

    AT_DUMP("== ", "entering mainLoop()", -1 );
    at_set_on_reader_closed(onATReaderClosed);
    at_set_on_timeout(onATTimeout);

    for (;;) {
        fd = -1;
        while  (fd < 0) {
            if (s_port > 0) {
                fd = socket_loopback_client(s_port, SOCK_STREAM);
            } else if (s_device_socket) {
                if (!strcmp(s_device_path, "/dev/socket/qemud")) {
                    /* Qemu-specific control socket */
                    fd = socket_local_client( "qemud",
                                              ANDROID_SOCKET_NAMESPACE_RESERVED,
                                              SOCK_STREAM );
                    if (fd >= 0 ) {
                        char  answer[2];

                        if ( write(fd, "gsm", 3) != 3 ||
                             read(fd, answer, 2) != 2 ||
                             memcmp(answer, "OK", 2) != 0)
                        {
                            close(fd);
                            fd = -1;
                        }
                   }
                }
                else
                    fd = socket_local_client( s_device_path,
                                            ANDROID_SOCKET_NAMESPACE_FILESYSTEM,
                                            SOCK_STREAM );
            } else if (s_device_path != NULL) {
                fd = open (s_device_path, O_RDWR);
                if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) {
                    /* disable echo on serial ports */
                    struct termios  ios;
                    tcgetattr( fd, &ios );
                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
                    ios.c_iflag = 0;
                    tcsetattr( fd, TCSANOW, &ios );
                }
            }
   

            if (fd < 0) {
                perror ("opening AT interface. retrying...");
                sleep(10);
                /* never returns */
            }
        }

        RLOGD("FD: %d", fd);

        s_closed = 0;
        ret = at_open(fd, onUnsolicited);

        if (ret < 0) {
            RLOGE ("AT error %d on at_open\n", ret);
            return 0;
        }

        RIL_requestTimedCallback(initializeCallback, NULL, &TIMEVAL_0);

        // Give initializeCallback a chance to dispatched, since
        // we don't presently have a cancellation mechanism
        sleep(1);

        waitForClose();
        RLOGI("Re-opening after close");
    }
}
示例#5
0
static void emulator_gemini_opensocket()
{
	int fd;
    		int ret;
		for (;;) {
       		 fd = -1;
			RLOGI("[Emu]emulator_gemini_opensocket_in\n");
			
			RLOGI("[Emu]s_device_socket %d\n",s_device_socket);
			RLOGI("[Emu]s_port %d\n",s_port);
			 while  (fd < 0) {
           			 if (s_port > 0) {
            			    fd = socket_loopback_client(s_port, SOCK_STREAM);
							RLOGI("[Emu]fd1 %d\n",fd);
          			  } else if (s_device_socket) {
            				    if (!strcmp(s_device_path, "/dev/socket/qemud")) {
	                			    /* Qemu-specific control socket */
	             			           fd = socket_local_client( "qemud",
	                                              ANDROID_SOCKET_NAMESPACE_RESERVED,
	                                              SOCK_STREAM );
								RLOGI("[Emu]fd2 %d\n",fd);	
	                 			   if (fd >= 0 ) {
	                 		         	   char  answer[2];

				                        if ( write(fd, "gsm", 3) != 3 ||
				                             read(fd, answer, 2) != 2 ||
				                             memcmp(answer, "OK", 2) != 0)
				                        {
				                            close(fd);
				                            fd = -1;
				                        }
                  		 	 	 }
		            	 	   }
		                	   else {
						  fd = socket_local_client( s_device_path,
                                            ANDROID_SOCKET_NAMESPACE_FILESYSTEM,
                                            SOCK_STREAM );
						}
							   RLOGI("[Emu]fd3 %d\n",fd);
                   			
            				} else if (s_device_path != NULL) {
                				fd = open (s_device_path, O_RDWR);
               				 if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) {
				                 	/* disable echo on serial ports */
				                    struct termios  ios;
				                    tcgetattr( fd, &ios );
				                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
							  ios.c_iflag = 0;		
				                    tcsetattr( fd, TCSANOW, &ios );
				                }
							 RLOGI("[Emu]fd4 %d\n",fd);
			            }

			            if (fd < 0) {
							 RLOGI("[Emu]fd<0");
			                perror ("opening AT interface. retrying...");
			                sleep(10);
			                /* never returns */
			            }
       		 }

		        s_closed = 0;
		        ret = at_open_emulator(fd, onUnsolicited,is_gemini_emulator);

		        if (ret < 0) {
		            RLOGE ("AT error %d on at_open\n", ret);
		            return 0;
		        }
			RLOGI("[Emu]RIL_requestTimedCallback");
			RIL_requestTimedCallback(initializeCallback, &s_pollSimId, &TIMEVAL_0);
#ifdef MTK_GEMINI
			RIL_requestTimedCallback(initializeCallback, &s_pollSimId2, &TIMEVAL_0);
#endif 
				RLOGI("[Emu]RIL_requestTimedCallback out");
			// Give initializeCallback a chance to dispatched, since
			// we don't presently have a cancellation mechanism
			sleep(1);
			
			waitForClose();
			RLOGI("Re-opening after close");

		}
}