Пример #1
0
/*
 * Set up process globals for the named service, to execute specified handler function
 */
bool ProcessGlobals::initialise(const char* _serviceName)
{
	// store the supplied service name

	serviceName = _serviceName;

	// create event source (event logger writes to stderr if this is null)

	hEventSource = registerServiceEventSource(serviceName);

	// load service parameters from the registry

	bool initOk = loadServiceParameters();

	// if configured, create the pair of event semaphores to wait on

	if (initOk)
	{
		hWaitForStart = createEventHandle();

		hWaitForStop = createEventHandle();

		initOk = ((hWaitForStart != NULL) && (hWaitForStop != NULL));
	}

	// if initialisation was not successful, clean up now

	if (!initOk)
	{
		cleanUp();
	}

	return initOk;
}
Пример #2
0
    UDPSocket::UDPSocket(void):
      m_con_port(0)
    {
      //  POSIX / Win32
#if defined(DUNE_SYS_HAS_SOCKET)
      m_handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if (m_handle == INVALID_SOCKET)
        throw NetworkError(DTR("unable to create socket"), DUNE_SOCKET_ERROR);

#  if defined(DUNE_OS_WINDOWS) && defined(DUNE_SYS_HAS_WSA_IOCTL)
      // To avoid cumbersome Windows connection reset error 10054 (WSACONNRESET)
      // Reference: http://support.microsoft.com/kb/263823
      DWORD dummy = 0;
      BOOL behavior = FALSE;

      if (WSAIoctl(m_handle, SIO_UDP_CONNRESET, &behavior, sizeof(behavior),
                   0, 0, &dummy, 0, 0) == SOCKET_ERROR)
      {
        if (GetLastError() != WSAEOPNOTSUPP)
        {
          throw NetworkError(DTR("setting up socket"), DUNE_SOCKET_ERROR);
        }
      }
#  endif
#else
      throw NotImplemented("UDPSocket");
#endif

      createEventHandle();
    }
Пример #3
0
    TCPSocket::TCPSocket(bool create):
      m_handle(INVALID_SOCKET)
    {
      if (create)
      {
        m_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

        if (m_handle == INVALID_SOCKET)
          throw NetworkError(DTR("unable to create socket"), getLastErrorMessage());

        disableSIGPIPE();
        createEventHandle();
      }
    }