Esempio n. 1
0
void
rehash(int signum) {
  Log(MT_MSG, "Signal caught, rehashing...");
  CleanUp(0);
  ParseConfig();
  StartListening();
}
Esempio n. 2
0
// ---------------------------------------------------------------------------
//  constructor
// ---------------------------------------------------------------------------
//
CEventManager::CEventManager(CImagePrintUiAppUi* aAppUi, CDpsEngine* aDpsEngine)
    : CActive(CActive::EPriorityStandard), iAppUi(aAppUi),iDpsEngine(aDpsEngine),
      iErrorState(EFalse)
    {
    CActiveScheduler::Add(this);
    StartListening();
    }
// EPOC default constructor can leave.
void CSuplSessionNotifier::ConstructL()
    {
    CActiveScheduler::Add(this);
    iRepository = CRepository::NewL(KCRUidSuplSettings);
    
    // Start listening
    StartListening();
    }
Esempio n. 4
0
/*******************************************************************************
*
* Name: VisItInitializeSocketAndDumpSimFile
*
* Purpose: Start listening, and write the file telling clients how to connect.
*
* Author: Jeremy Meredith, B Division, Lawrence Livermore National Laboratory
*
* Modifications:
*   Shelly Prevost, Wed Jan 25 08:50:44 PST 2006
*   Added the guifile argument.
*
*   David Camp, Thu Jan 13 11:15:00 PST 2011
*   Close file if an error occurred.
*
*******************************************************************************/
int VisItInitializeSocketAndDumpSimFile(const char *name,
                                        const char *comment,
                                        const char *path,
                                        const char *inputfile,
                                        const char *guifile,
                                        const char *absoluteFilename)
{
    FILE *file;

    EnsureSimulationDirectoryExists();
    CreateRandomSecurityKey();
    
    if ( !absoluteFilename )
    {
        snprintf(simulationFileName, 255, "%s/.visit/simulations/%012d.%s.sim1",
                 GetHomeDirectory(), (int)time(NULL), name);
    }
     else
     {
          snprintf(simulationFileName, 255, "%s", absoluteFilename);
     }
       
    file = fopen(simulationFileName, "wt");
    if (!file)
    {
        return FALSE;
    }

    atexit(RemoveSimFile);

    if (!GetLocalhostName())
    {
       fclose(file);
       return FALSE;
    }

    if (!StartListening())
    {
       fclose(file);
       return FALSE;
    }

    fprintf(file, "host %s\n", localhost);
    fprintf(file, "port %d\n", listenPort);
    fprintf(file, "key %s\n", securityKey);
    if (path)
        fprintf(file, "path %s\n", path);
    if (inputfile)
        fprintf(file, "inputfile %s\n", inputfile);
    if (comment)
        fprintf(file, "comment %s\n", comment);
     if ( guifile )
       fprintf(file, "uiFile %s\n", guifile);

    fclose(file);

    return TRUE;
}
ECode CGeckoNetworkManager::Start()
{
    mShouldBeListening = TRUE;

    if (mShouldNotify) {
        FAIL_RETURN(StartListening());
    }
    return NOERROR;
}
Esempio n. 6
0
bool CListenSocket::Rebind()
{
	if (thePrefs.GetPort() == m_port)
		return false;

	Close();
	KillAllSockets();

	return StartListening();
}
// ---------------------------------------------------------
// CSuplSessionNotifier::RunL
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSuplSessionNotifier::RunL()
    {
     TInt event;
     iRepository->Get(KSuplSessionDBEvent, event);
     TReal sessionID;
     iRepository->Get(KSuplSessionDBChangedSessionId, sessionID);
     MSuplSessionObserver::TSuplSessionEventType eventType = (MSuplSessionObserver::TSuplSessionEventType)event;
     iObserver.HandleSuplSessionChangeL(eventType,sessionID);
     
     StartListening();
    }
ECode CGeckoNetworkManager::EnableNotifications()
{
    // We set mShouldNotify *after* calling updateNetworkType() to make sure we
    // don't notify an eventual change in mNetworkType.
    FAIL_RETURN(UpdateNetworkType());
    mShouldNotify = true;

    if (mShouldBeListening) {
      FAIL_RETURN(StartListening());
    }

    return NOERROR;
}
Esempio n. 9
0
// ---------------------------------------------------------------------------
// 
// ---------------------------------------------------------------------------
//	
void CEventManager::RunError()
    {
    FLOG(_L("[IMAGEPRINTUI] CEventManager::RunError"));
    
    StartListening();
    if(iStatus.Int() == KErrTimedOut)
    	{
    	FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; RunError, timed out"));	
    	}
    else if( iStatus.Int() == KErrUsbInterfaceNotReady)	
		{
		FLOG(_L("[IMAGEPRINTUI] CEventManager::KErrUsbInterfaceNotReady"));
		// iAppUi->NotifyEventL(KErrUsbInterfaceNotReady);
		}		
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager::RunError iStatus is is %d"), iStatus.Int() ));
    // iAppUi->NotifyEventL(CEventManager::ESeriousError);
    }
Esempio n. 10
0
void GSNetworkListener::Slot3()
{
	switch(myMenustatus)
	{
		case networklistener::CHOOSE:
			StartListening();
			myMenustatus = networklistener::LISTENING;
			Gui::SetMenupointText(2, "Is Listening...");
			Gui::SetMenupointText(4, "Stop Listening");
			Gui::ActivateMenupoint(0, false);
			Gui::ActivateMenupoint(1, false);
		break;
		
		case networklistener::CONNECTED:
			myNextState = new GSNetworkGame(GameState::myWindow, GameState::mySettings, mySocket);
			myMenustatus = networklistener::CHOOSE;
			myListenerThread.wait();
			mySocket = NULL;
			myNextStatus = NEXTSTATE;
		break;
		
		default: break;
	}
}
Esempio n. 11
0
void CW32SocketServer::Start()
{
	StartListening();
}
Esempio n. 12
0
// ---------------------------------------------------------------------------
// Handles situation depends on result after calling DpsEventNotify 
// 
// ---------------------------------------------------------------------------
//
void CEventManager::HandleReturnStatusL()
	{
    FLOG(_L("[IMAGEPRINTUI]>>> CEventManager; HandleReturnStatus"));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager event value is %d"), iEventRequest.iEvent ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iPrintStatus is %x"), iEventRequest.iPrinterEvent.iRepParam.iPrintStatus ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iJobStatus is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobStatus ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iErrorStatus hex is %x"), iEventRequest.iPrinterEvent.iRepParam.iErrorStatus ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iJobEndReason is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iPaperMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iPaperMinor ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iInkMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iHardMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iHardMinor ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iFileMinor is %x"), iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iFileMinor ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iDisconnectEnable is %d"), iEventRequest.iPrinterEvent.iRepParam.iDisconnectEnable ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iCapabilityChange is %d"), iEventRequest.iPrinterEvent.iRepParam.iCapabilityChange ));
    FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager iNewJobOk is is %d"), iEventRequest.iPrinterEvent.iRepParam.iNewJobOk ));
    
    
	if(iEventRequest.iEvent == EDpsEvtNotifyJobStatus)	
		{
		FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; NotifyPrintProgress"));
		FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager  iImagesPrinted is %d"), iEventRequest.iJobEvent.iRepParam.iImagesPrinted ));
		FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CEventManager  iProgress is %d"), iEventRequest.iJobEvent.iRepParam.iProgress ));
	    iAppUi->NotifyPrintProgress(iEventRequest.iJobEvent.iRepParam.iImagesPrinted, 
	                                 iEventRequest.iJobEvent.iRepParam.iProgress);
		}
		
	else if(iEventRequest.iEvent == EDpsEvtNotifyDeviceStatus)
		    {		    		    
		    FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; HandleReturnStatus, EDpsEvtNotifyDeviceStatus"));
		    iAppUi->NotifyPrintStatus(iEventRequest.iPrinterEvent.iRepParam.iPrintStatus);
		    
		    HandleJobStatusL(iEventRequest.iPrinterEvent.iRepParam.iJobStatus);
		    
		    HandleErrorStatusL(iEventRequest.iPrinterEvent.iRepParam.iErrorStatus);
		    
		    if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorPaper)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorPaper"));
				HandlePaperErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iPaperMinor);
				}
			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorInk)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorInk"));
				HandleInkErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iInkMinor);
				}
			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorFile)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorFile"));
				HandleFileErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iFileMinor);
				}
			else if(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iMajor == EDpsJobErrorHardware)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::EDpsJobErrorHardware"));
				HandleHardwareErrorL(iEventRequest.iPrinterEvent.iRepParam.iJobEndReason.iHardMinor);
				}			
		    
		    if(iEventRequest.iPrinterEvent.iRepParam.iNewJobOk)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::HandleDeviceStatusL, NewJob is OK"));
				iAppUi->NotifyEventL(CEventManager::ENewJobOK );
		    	}
	        //capability change	
			else if(iEventRequest.iPrinterEvent.iRepParam.iCapabilityChange)
				{
				FLOG(_L("[IMAGEPRINTUI] CEventManager::capability change"));
				iAppUi->NotifyEventL(CEventManager::ECapabilityChange);
				}
		    }
    FLOG(_L("[IMAGEPRINTUI]<<< CEventManager; HandleReturnStatus, next call StartListening"));		    
	StartListening();
	}
Esempio n. 13
0
void CListenSocket::OnAccept(int nErrorCode)
{
	if (!nErrorCode)
	{
		m_nPendingConnections++;
		if (m_nPendingConnections < 1){
			ASSERT(0);
			m_nPendingConnections = 1;
		}

		if (TooManySockets(true) && !CGlobalVariable::serverconnect->IsConnecting()){
			StopListening();
			return;
		}
		else if (!bListening)
			ReStartListening(); //If the client is still at maxconnections, this will allow it to go above it.. But if you don't, you will get a lowID on all servers.

		uint32 nFataErrors = 0;
		while (m_nPendingConnections > 0)
		{
			m_nPendingConnections--;

			CClientReqSocket* newclient;
			SOCKADDR_IN SockAddr = {0};
			int iSockAddrLen = sizeof SockAddr;
			if (thePrefs.GetConditionalTCPAccept() && !thePrefs.GetProxySettings().UseProxy)
			{
				_iAcceptConnectionCondRejected = 0;
				SOCKET sNew = WSAAccept(m_SocketData.hSocket, (SOCKADDR*)&SockAddr, &iSockAddrLen, AcceptConnectionCond, 0);
				if (sNew == INVALID_SOCKET){
					DWORD nError = GetLastError();
					if (nError == WSAEWOULDBLOCK){
						DebugLogError(LOG_STATUSBAR, _T("%hs: Backlogcounter says %u connections waiting, Accept() says WSAEWOULDBLOCK - setting counter to zero!"), __FUNCTION__, m_nPendingConnections);
						m_nPendingConnections = 0;
						break;
					}
					else{
						if (nError != WSAECONNREFUSED || _iAcceptConnectionCondRejected == 0){
							DebugLogError(LOG_STATUSBAR, _T("%hs: Backlogcounter says %u connections waiting, Accept() says %s - setting counter to zero!"), __FUNCTION__, m_nPendingConnections, GetErrorMessage(nError, 1));
							nFataErrors++;
						}
						else if (_iAcceptConnectionCondRejected == 1)
							theStats.filteredclients++;
					}
					if (nFataErrors > 10){
						// the question is what todo on a error. We cant just ignore it because then the backlog will fill up
						// and lock everything. We can also just endlos try to repeat it because this will lock up eMule
						// this should basically never happen anyway
						// however if we are in such a position, try to reinitalize the socket.
						DebugLogError(LOG_STATUSBAR, _T("%hs: Accept() Error Loop, recreating socket"), __FUNCTION__);
						Close();
						StartListening();
						m_nPendingConnections = 0;
						break;
					}
					continue;
				}
				newclient = new CClientReqSocket;
				VERIFY( newclient->InitAsyncSocketExInstance() );
				newclient->m_SocketData.hSocket = sNew;
				newclient->AttachHandle(sNew);

				AddConnection();
			}
			else
			{
				newclient = new CClientReqSocket;
				if (!Accept(*newclient, (SOCKADDR*)&SockAddr, &iSockAddrLen)){
					newclient->Safe_Delete();
					DWORD nError = GetLastError();
					if (nError == WSAEWOULDBLOCK){
						DebugLogError(LOG_STATUSBAR, _T("%hs: Backlogcounter says %u connections waiting, Accept() says WSAEWOULDBLOCK - setting counter to zero!"), __FUNCTION__, m_nPendingConnections);
						m_nPendingConnections = 0;
						break;
					}
					else{
						DebugLogError(LOG_STATUSBAR, _T("%hs: Backlogcounter says %u connections waiting, Accept() says %s - setting counter to zero!"), __FUNCTION__, m_nPendingConnections, GetErrorMessage(nError, 1));
						nFataErrors++;
					}
					if (nFataErrors > 10){
						// the question is what todo on a error. We cant just ignore it because then the backlog will fill up
						// and lock everything. We can also just endlos try to repeat it because this will lock up eMule
						// this should basically never happen anyway
						// however if we are in such a position, try to reinitalize the socket.
						DebugLogError(LOG_STATUSBAR, _T("%hs: Accept() Error Loop, recreating socket"), __FUNCTION__);
						Close();
						StartListening();
						m_nPendingConnections = 0;
						break;
					}
					continue;
				}

				AddConnection();

				if (SockAddr.sin_addr.S_un.S_addr == 0) // for safety..
				{
					iSockAddrLen = sizeof SockAddr;
					newclient->GetPeerName((SOCKADDR*)&SockAddr, &iSockAddrLen);
					DebugLogWarning(_T("SockAddr.sin_addr.S_un.S_addr == 0;  GetPeerName returned %s"), ipstr(SockAddr.sin_addr.S_un.S_addr));
				}

				ASSERT( SockAddr.sin_addr.S_un.S_addr != 0 && SockAddr.sin_addr.S_un.S_addr != INADDR_NONE );

				if (CGlobalVariable::ipfilter->IsFiltered(SockAddr.sin_addr.S_un.S_addr)){
					if (thePrefs.GetLogFilteredIPs())
						AddDebugLogLine(false, _T("Rejecting connection attempt (IP=%s) - IP filter (%s)"), ipstr(SockAddr.sin_addr.S_un.S_addr), CGlobalVariable::ipfilter->GetLastHit());
					newclient->Safe_Delete();
					theStats.filteredclients++;
					continue;
				}

				if (CGlobalVariable::clientlist->IsBannedClient(SockAddr.sin_addr.S_un.S_addr)){
					if (thePrefs.GetLogBannedClients()){
						CUpDownClient* pClient = CGlobalVariable::clientlist->FindClientByIP(SockAddr.sin_addr.S_un.S_addr);
						AddDebugLogLine(false, _T("Rejecting connection attempt of banned client %s %s"), ipstr(SockAddr.sin_addr.S_un.S_addr), pClient->DbgGetClientInfo());
					}
					newclient->Safe_Delete();
					continue;
				}
			}
			newclient->AsyncSelect(FD_WRITE | FD_READ | FD_CLOSE);
		}

		ASSERT( m_nPendingConnections >= 0 );
	}
}
Esempio n. 14
0
File: main.c Progetto: ebichu/dd-wrt
int
main( int argc, char **argv ) {
   int num_polled = 1;
   struct pollfd *polls;
   struct sockaddr_in incoming;
   int i, n, pos, len;
   int new_fd;
   socklen_t addr_len;
   Connection *conn;
   IPP *response;

   signal( SIGUSR1, quit_handler );

   // Temp printer for now
   if( argc < 2 ) {
     fprintf(stderr, "Missing argument pointing to location of printer definition file.\n" );
     exit(1);
   }

   if(!init_printers( argv[1] )) {
     fprintf( stderr, "Unable to load printer definition file %s\n", argv[1] );
     exit(1);
   }

   new_fd = StartListening();

   polls = malloc( sizeof( struct pollfd )  * MAX_CLIENTS);
   polls[0].fd = new_fd;
   polls[0].events = POLLIN;

   for(;;) {
     // printf(".");
     for( conn = list_conn( NULL ), num_polled = 1; conn != NULL; conn = list_conn( conn ) ) {
       if( conn->state == CONN_BEGIN || conn->state == CONN_PRINTING_READ ) {
         polls[num_polled].fd = conn->fd;
         polls[num_polled++].events = POLLIN;
       } else if( conn->state == CONN_OUTPUT ) {
         polls[num_polled].fd = conn->fd;
         polls[num_polled++].events = POLLOUT;
       }
     }
     for( i = 0; i < array_len( printers ); i++ ) {
       printer = array_get( printers, i );
       if( printer->state == PRINTER_PRINTING_WRITE ) {
         polls[num_polled].fd = printer->fd;
         polls[num_polled++].events = POLLOUT;
       }
     }

     poll( polls, num_polled, -1 );
     // printf("o" );
     for( i = 0; i < num_polled; i++ ) {
       if( polls[i].revents & POLLIN ) {
         // Read
         if( i == 0 ) { // Special case..
           addr_len = sizeof( struct sockaddr_in );
           new_fd = accept( polls[i].fd, (struct sockaddr *)&(incoming), &addr_len );
           add_conn( new_fd );
         } else {
           if( ( conn = get_conn( polls[i].fd ) ) ) {
             process_conn( conn );
           }
         }
       } else if ( polls[i].revents & POLLNVAL ) {
         if( ( conn = get_conn( polls[i].fd ) ) )
           remove_conn( conn );
       } else if ( polls[i].revents & POLLOUT ) {
         if( ( conn = get_conn( polls[i].fd ) ) ) {
           if( ( n = write( conn->fd, conn->buffer+conn->buf_ptr, conn->used-conn->buf_ptr ) ) ) {
             conn->buf_ptr += n;
             if( conn->buf_ptr == conn->used ) {
               close( conn->fd );
               remove_conn( conn );
             }
           }
         } else {
           int e;

           for( e = 0; e < array_len( printers ); e++ ) {
             printer = array_get( printers, e );
             if( printer->fd == polls[i].fd ) { 
               if( ( n = write( printer->fd, printer->buffer+printer->buf_ptr, printer->used-printer->buf_ptr ) ) == 0 ) {
#if 0
                 // ERROR WRITING TO PRINTER
                 // Simple error support -- close printer fd
                 if( ( conn = get_conn( printer->jobs->job.fd ) ) ) {
                   fprintf( stderr, "Print job error.\n" );
                   response = ipp_new();
                   response->response = 0x0504;
                   response->version = 256; // IPP 1.0
                   response->request_id = conn->ipp->request_id;
                   ipp_add_tag( response, IPP_TAG_OPERATIONS, NULL, NULL, 0, 0 );
                   ipp_copy_tag( response, conn->ipp, IPP_TAG_OPERATIONS, "attributes-charset" );
                   ipp_copy_tag( response, conn->ipp, IPP_TAG_OPERATIONS, "attributes-natural-language" );
                   len = ipp_write( response, NULL, len );
                   pos = sprintf( conn->buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/ipp\r\nContent-Length: %d\r\n\r\n", len );
                   ipp_write( response, conn->buffer+pos, len );
                   conn->used = len + pos;
                   conn->buf_ptr = 0;
                   conn->state = CONN_OUTPUT;
                   ipp_free( response );
                 }
                 fprintf( stderr, "Marking printer closed.\n" );
                 close(printer->fd );
                 printer->state = PRINTER_CLOSED;
#endif /* 0 */
               } else {
                 printer->buf_ptr += n;
                 if( printer->buf_ptr == printer->used ) {
                   printer->state = PRINTER_PRINTING_WAIT;
                   printer->buf_ptr = printer->used = 0;
                   if( ( conn = get_conn( printer->jobs->job.fd ) ) == NULL ) {
                     printf( "Bad printer state.\n" );
                   }
                   if( conn->ipp->data_left )
                     conn->state = CONN_PRINTING_READ;
                   else {
                     int pos, len, val;
                     struct _ipp_jobs *old_job;
                     IPP *response;
                     // Generate a done message
                     response = ipp_new();
                     response->response = 0x0000; // Success
                     response->request_id = conn->ipp->request_id;
                     response->version = 256;
                     ipp_add_tag( response, IPP_TAG_OPERATIONS, NULL, NULL, 0, 0 );
                     ipp_copy_tag( response, conn->ipp, IPP_TAG_OPERATIONS, "attributes-charset" );
                     ipp_copy_tag( response, conn->ipp, IPP_TAG_OPERATIONS, "attributes-natural-language" );
                     /* 2004/11/8 : Added to make XP printer utility report success status*/
                     ipp_add_tag( response, IPP_TAG_TEXT_WO_LANG, "status-message", "successful-ok", strlen( "successful-ok" ), 0 );
    				 ipp_add_tag( response, IPP_TAG_JOBS, NULL, NULL, 0, 0 );
    				 val = printer->jobs->job.id;
    				 ipp_add_tag( response, IPP_TAG_INTEGERS, "job-id", &val, 4, 0 );
    				 val = 9;
    				 ipp_add_tag( response, IPP_TAG_ENUM, "job-state", &val, 4, 0 ); /* 9 = COMPLETED */
                     // Done
                     len = ipp_write( response, NULL, len );
                     pos = sprintf( conn->buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/ipp\r\nContent-Length: %d\r\n\r\n", len );
                     ipp_write( response, conn->buffer + pos, len );
                     conn->used = len + pos;
                     conn->buf_ptr = 0;
                     conn->state = CONN_OUTPUT;
                     /* 2004/11/8: added to free response */
          			 ipp_free( response );
                     // The JOB being is printed is ALWAYS the first one
                     old_job = printer->jobs;
                     printer->jobs = old_job->next;
                     free( old_job ); // Free the job

                     printf( "Going to next job...\n" );
                     if( printer->jobs ) {
                       if( ( conn = get_conn( printer->jobs->job.fd ) ) ) {
                         if( conn->buf_ptr < conn->used ) {
                           memcpy( printer->buffer, conn->buffer + conn->buf_ptr, conn->used - conn->buf_ptr );
                           printer->used = conn->used - conn->buf_ptr;
                           printer->buf_ptr = 0;
                           printer->state = PRINTER_PRINTING_WRITE;
                           conn->state = CONN_PRINTING_WAIT;
                           conn->ipp->data_left -= conn->used - conn->buf_ptr;
                         } else {
                           if( conn->ipp->data_left ) {
                             printer->state = PRINTER_PRINTING_WAIT;
                             conn->state = CONN_PRINTING_READ;
                           }
                         }
                       } else {
                         printf( "Unable to get connection for FD - %d.\n", printer->jobs->job.fd );
                       }
                     } else {
                        /* printer->state = PRINTER_OPEN; */
                     	/* 2004/11/5 : put back into closed state so that kernel can remove lp0 when printer unplugged */
  	  					close(printer->fd);
  	  					printer->fd = 0;
  	  					printer->state = PRINTER_CLOSED;
                     }
                   }
                 } 
               }
             }
           }
         }  
       }
     }
  }
}
Esempio n. 15
0
HRESULT InitializeTAPI()
{
    
    LogMessage("InitializeTAPI: started");

    HRESULT hr = E_FAIL;
        

    //
    // cocreate the TAPI object
    //

    hr = CoCreateInstance(
                          CLSID_TAPI,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_ITTAPI,
                          (LPVOID *)&g_pTapi
                         );

    if (FAILED(hr))
    {
        LogError("InitializeTAPI: failed to CoCreateInstance TAPI");

        return hr;
    }


    //
    // cannot use tapi until it's initialized
    //

    hr = g_pTapi->Initialize();

    if (FAILED(hr))
    {
        LogError("InitializeTAPI: TAPI failed to initialize");

        g_pTapi->Release();
        g_pTapi = NULL;
        
        return hr;
    }


    //
    // register the callback object that will receive tapi notifications
    //

    hr = RegisterCallback();

    if (FAILED(hr))
    {
        LogError("InitializeTAPI: failed to register callback");

        g_pTapi->Shutdown();
        g_pTapi->Release();
        g_pTapi = NULL;
        
        return hr;
    }


    //
    // we want to be notified of these events:
    //
   
    hr = g_pTapi->put_EventFilter(TE_CALLNOTIFICATION |
                                  TE_CALLSTATE |
                                  TE_CALLMEDIA);

    if (FAILED(hr))
    {
        LogError("InitializeTAPI: Failed to put_EventFilter");

        //
        // unregister callback
        //

        UnRegisterCallBack();

        //
        // shutdown and release TAPI
        //

        g_pTapi->Shutdown();
        g_pTapi->Release();
        g_pTapi = NULL;

        return hr;
    }


    //
    // start listening on the addresses that support audio
    //

    hr = StartListening();

    if (S_OK != hr)
    {
        LogError("InitializeTAPI: Failed to start listening");

        //
        // unregister callback
        //

        UnRegisterCallBack();

        //
        // shutdown and release TAPI
        //

        g_pTapi->Shutdown();
        g_pTapi->Release();
        g_pTapi = NULL;

        return hr;
    }

    LogMessage("InitializeTAPI: succeeded");

    return S_OK;
}
Esempio n. 16
0
void Server::Start()
{
    StartListening();
    StartAcceptingConnections();
}