예제 #1
0
파일: main.c 프로젝트: longyn/OpENer
void
leaveStack(int pa_nSig)
{
  (void) pa_nSig; /* kill unused parameter warning */
  OPENER_TRACE_STATE("got signal HUP\n");
  g_nEndStack = 1;
}
예제 #2
0
void
CheckAndHandleUdpUnicastSocket()
{
	int nReceived_size;
	int nRemainingBytes;
	int nReplyLen;
	EipUint8 *rxp;
	struct sockaddr_in stFrom;
	unsigned long nFromLen;

	/* see if this is an unsolicited inbound UDP message */
	if (true == checkSocketSet(g_network_status.udp_unicast_listener))
	{

		nFromLen = sizeof(stFrom);

		OPENER_TRACE_STATE(
			"networkhandler: unsolicited UDP message on EIP broadcast socket\n");

		/*Handle udp broadcast messages */
		nReceived_size = recvfrom(g_network_status.udp_unicast_listener,
			g_ethernet_communciation_buffer, PC_OPENER_ETHERNET_BUFFER_SIZE, 0,
			(struct sockaddr *) &stFrom, &nFromLen);

		if (nReceived_size <= 0)
		{ /* got error */
			OPENER_TRACE_ERR(
				"networkhandler: error on recvfrom udp broadcast port: %s\n",
				strerror(errno));
			return;
		}

		OPENER_TRACE_INFO("Data received on udp:\n");

		rxp = &g_ethernet_communciation_buffer[0];
		do
		{
			nReplyLen = HandleReceivedExplictUdpData(
				g_network_status.udp_unicast_listener, &stFrom, rxp, nReceived_size,
				&nRemainingBytes, true);

			rxp += nReceived_size - nRemainingBytes;
			nReceived_size = nRemainingBytes;

			if (nReplyLen > 0)
			{
				OPENER_TRACE_INFO("reply sent:\n");

				/* if the active fd matches a registered UDP callback, handle a UDP packet */
				if (sendto(g_network_status.udp_unicast_listener,
					(char *)g_ethernet_communciation_buffer, nReplyLen, 0,
					(struct sockaddr *) &stFrom, sizeof(stFrom)) != nReplyLen)
				{
					OPENER_TRACE_INFO(
						"networkhandler: UDP response was not fully sent\n");
				}
			}
		} while (nRemainingBytes > 0);
	}
}
예제 #3
0
void
CheckAndHandleTcpListenerSocket()
{
  int newfd;
  /* see if this is a connection request to the TCP listener*/
  if (true == checkSocketSet(g_network_status.tcp_listener))
    {
      OPENER_TRACE_INFO("networkhandler: new TCP connection\n");

      newfd = accept(g_network_status.tcp_listener, NULL, NULL);
      if (newfd == -1)
        {
          OPENER_TRACE_ERR("networkhandler: error on accept: %s\n", strerror(errno));
          return;
        }

      FD_SET(newfd, &master);
      /* add newfd to master set */
      if (newfd > fdmax)
        {
          fdmax = newfd;
        }

      OPENER_TRACE_STATE(
          "networkhandler: opened new TCP connection on fd %d\n",
          newfd);
    }
}
예제 #4
0
void
CheckAndHandleConsumingUdpSockets()
{
  int nReceived_size;
  struct sockaddr_in stFrom;
#ifndef WIN32
  socklen_t nFromLen;
#else
  unsigned long nFromLen;
#endif

  ConnectionObject *pstRunner = g_active_connection_list;
  ConnectionObject *pstCurrent;

  /* see a message on one of the registered UDP sockets has been received     */
  while (NULL != pstRunner)
    {
      pstCurrent = pstRunner;
      pstRunner = pstRunner->next_connection_object; /* do this at the beginning as the close function may can make the entry invalid */

      if ((-1 != pstCurrent->socket[kUdpCommuncationDirectionConsuming])
          && (true == checkSocketSet(pstCurrent->socket[kUdpCommuncationDirectionConsuming])))
        {
          nFromLen = sizeof(stFrom);
          nReceived_size = recvfrom(pstCurrent->socket[kUdpCommuncationDirectionConsuming],
              g_ethernet_communciation_buffer, PC_OPENER_ETHERNET_BUFFER_SIZE, 0,
              (struct sockaddr *) &stFrom, &nFromLen);
          if (0 == nReceived_size)
            {
              OPENER_TRACE_STATE("connection closed by client\n");
              pstCurrent->connection_close_function(pstCurrent);
              continue;
            }

          if (0 > nReceived_size)
            {
              OPENER_TRACE_ERR("networkhandler: error on recv: %s\n", strerror(errno));
              pstCurrent->connection_close_function(pstCurrent);
              continue;
            }

          HandleReceivedConnectedData(g_ethernet_communciation_buffer, nReceived_size,
              &stFrom);

        }
    }
}
예제 #5
0
파일: main.c 프로젝트: EIPStackGroup/OpENer
void LeaveStack(int signal) {
  (void) signal;       /* kill unused parameter warning */
  OPENER_TRACE_STATE("got signal HUP\n");
  g_end_stack = 1;
}