Beispiel #1
0
void CloseCommServer( SOCK *srv, SOCK *clnt )
{
	CloseServer(clnt);
	CloseServer(srv);
	delete SendMutex; SendMutex = NULL;
	delete ReceiveMutex; ReceiveMutex = NULL;
#ifdef COMMTIMING
	if( sendRcvDelays > 0 ){
		QTils_LogMsgEx( "Average communications delay over %lu messages: %gs", sendRcvDelays, cumSendRcvDelay/sendRcvDelays );
		sendRcvDelays = 0;
		cumSendRcvDelay = 0.0;
	}
#endif
}
Beispiel #2
0
int main(int argc, const char* argv[])
{
    HWND hWnd;
    MSG msg;
    const char* host = DEFAULT_HOST;
    const char* port = DEFAULT_PORT;
    if (argc > 2)
    {
        host = argv[1];
        port = argv[2];
    }

    hWnd = IntiInstance((HINSTANCE)GetModuleHandle(NULL));
    CHECK(InitializeServer(hWnd, host, atoi(port)));

    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.message == WM_SOCKET)
        {
            SOCKET fd = msg.wParam;
            int event = WSAGETSELECTEVENT(msg.lParam);
            int error = WSAGETSELECTERROR(msg.lParam);
            HandleNetEvents(hWnd, fd, event, error);
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    CloseServer();
    return 0;
}
Beispiel #3
0
// 关闭服务
void CSocketServerDlg::OnBnClickedButtonClose()
{
	CloseServer();
	CWnd *pWnd = GetDlgItem(IDC_BUTTON_OPEN);
	pWnd->EnableWindow(TRUE);
	pWnd = GetDlgItem(IDC_BUTTON_CLOSE);
	pWnd->EnableWindow(FALSE);
}
void CHtiIPCommServer::SessionClosed()
    {
    // Die if no more sessions
    if ( --iNrOfSessions == 0 )
        {
        HTI_LOG_TEXT( "HtiIPCommServer no more sessions - dying..." );
        CloseServer();
        }
    }
Beispiel #5
0
void CMyServer::Stop()
{
    if (m_bPortActive)
    {
        m_bPortActive = false;
        CloseServer(m_uPortNum);
        trace_log(SYS, "Service Port[%d] Closed.", m_uPortNum);
    }
}
Beispiel #6
0
/*server engine start function */
int main(int argc,char *argv[])
{
    char * Ip_Addr = NULL;
    char * sPort;
    char * tmpptr;
    char * ServerId = NULL;
    int Port;
    ServerId = argv[1];
    int new_fd,i,j,thread_no;
    debug_print(("Server Engine Open!\n"));
    /*初始化任务队列*/
    p = (tQueue *)malloc(sizeof(struct Queue));
    InitQueue(p);
    /*创建MAX_THREADNUM个线程,并初始化该线程对应的信号量*/
    for(i = 0;i < MAX_THREADNUM ; i++)
    {
        thread_no = i;
        sem_init(&pSems[i],0,0); //初始化线程信号量
        if(pthread_create(&thread_id[i] ,NULL,(void*)AllocateTask,(void*)thread_no) != 0)
        {
            fprintf(stderr,"pthread_create Error,%s:%d\n",__FILE__,__LINE__);
            exit(-1);
        }
    }         
    ServerPrepare(ServerId);    
    printf("server engine open!\n");
    pthread_mutex_init(&mutex, NULL);
    while(1)
    {
        new_fd = ServerOpen();
        ptask = (tQueueNode *)malloc(sizeof(struct QueueNode));
        ptask->sockfd = new_fd;
        tmpptr = RecvData(new_fd);
        memcpy(ptask->pBuf,tmpptr,strlen(tmpptr)+1);
        ptask->bufsize = strlen(ptask->pBuf);
        debug_print(("ptask you want insert:sockfd is %d,pBuf is %s,bufsize is %d\n",ptask->sockfd,\
                                                                               ptask->pBuf,\
                                                                               ptask->bufsize));
        InQueue(p,ptask);   //如果收到数据则入队等候处理
        j = (rand()%3);     //随机唤醒其中的一个线程将资源分配给该线程
        debug_print(("V op +%d thread\n",j));
        sem_post(&pSems[j]);   //用信号量v操作将资源数目+1
    }
    ServerCloseinfo(ServerId);
    CloseServer();
    for(i = 0;i < MAX_THREADNUM;i++)
    {
        sem_destroy(&pSems[i]);
        DeleteQueue(p);
    } 
    return 0;
}
/* State behaviour */
void behaviour_h2h_start_connect(state_ptr state)
{
  uint8_t i;
  /* Set events to react to */
  state->back = h2h_start_connect_to_main;
  state->h2h_start_connect = h2h_start_connect_to_h2h_ongoing;

  /* Do state actions */

  /*Clean devices names */
  for( i = 1; i < 5;i++)
  {
    item_area_set_text(&menu_h2h_devices.items[i].item.area," ");
    menu_h2h_devices.items[i].item.area.is_active = GUI_INACTIVE;
  }
  item_area_set_text(&menu_h2h_devices.items[6].item.area,"Searching for devices...");
  /* Set menu */
  osMutexWait(mutex_menuHandle, osWaitForever);
  menu_copy(&menu_h2h_devices, &current_menu);
  osMutexRelease(mutex_menuHandle);

  /* Display menu */
  for (i = 0; i < menu_h2h_devices.item_num; i++)
  {
    while (osMailPut(queue_lcdHandle, (void *) &menu_h2h_devices.items[i]) != osOK)
    {
      osDelay(1);
    }
  }

  /* Do state actions */
  /* We close and reopen the spp port in case of "zombie" connection*/
  CloseServer();
  OpenServer(); 
  Inquiry(TIMEOUT);
}