deps/PicklingTools170Release/M2k/udpif/udpservice.cc
void UDPService::incomingData_ ()
{ 
  int_u1               buffer[8192];
  int_4                length = sizeof(buffer);
  int_u4               flags (0);   
  struct  sockaddr_in  client_addr;
  int_4                addrlen = sizeof(client_addr);
  int_4                NumBytes;


  try {
    //
    // recv()
    // recvfrom() returns;  n > 0:  # bytes read
    //                      n = 0:  no msg/datagram avail (UNBLOCKED);
    //                              we do NOT use UNBLOCKED reads though..
    //                              or peer has done orderly shutdown (TCP only)
    //                      n < 0:  "something wicked this way comes..."
    //                              sets errno; throws exception
    //
        NumBytes = UDPSocketLib::UDP_recvFrom   (private_->socket_fd,
                                                 (unsigned char *)buffer, 
                                                 length, 
                                                 flags, 
                                                 &client_addr, 
                                                 addrlen);
        if (NumBytes > 0) {
          char  clientHost[64];
          int_4 len = sizeof(clientHost);
          UDPSocketLib::UDP_getHostByAddr (clientHost, len, &client_addr);
          string name (clientHost);
          log_.message("incomingData_::[UDP_recvFrom <clientAddr>]  NumBytes= " + 
                       Stringize(NumBytes) + ";  from <" + name + "(" + 
                       inet_ntoa(client_addr.sin_addr) + ")" + ":"+
                       Stringize(ntohs(client_addr.sin_port)) + ">");
        }

  } catch (const SocketLowLevelEx& e) {
      log_.error ("UDPService::[incomingData_]- Read error; "+e.problem());
    }

  //
  // No data...
  //
  if (NumBytes == 0) {
    log_.message("UDPService::[incomingData_]- No Data");
    //closeNetworkPort_();
  }
  //
  // ERROR- UDP socket read error
  //
  else if (NumBytes < 0) {
    log_.error("UDPService::[incomingData_]- UDP socket read error; closing port...");
    closeNetworkPort_();
  }
  
  debugUDPOutput_ ((unsigned char *)buffer, NumBytes);

}
//
// Preconditions: 
//
// Postconditions:
//
// Parameters:
//
// Description:
//
//  Called from Service::takeWakeUpCall() interrupt service routine for 
//  processing WakeOnSocket "socket" changes.  Assume UDP datagram arrival;
//  read buffer into application from TCP/IP (UDP) suite and process 
//  application message/data.
//
//  NOTE: This is a virtual function and is intended to be extended for 
//  application level processing of data.  This default just reads data and 
//  prints hex to screen.
//        
//
//






Called from Service::takeWakeUpCall() interrupt service routine for
processing WakeOnSocket "socket" changes.  Assume UDP datagram arrival;
read buffer into application from TCP/IP (UDP) suite and process
application message/data.

This is a virtual function and is intended to be extended for
application level processing of data.  This default just reads data and
prints hex to screen.
Called from Service :: takeWakeUpCall () interrupt service routine for processing WakeOnSocket " socket " changes . Assume UDP datagram arrival ; read buffer into application from TCP / IP ( UDP ) suite and process application message / data . This is a virtual function and is intended to be extended for application level processing of data . This default just reads data and prints hex to screen .
void UDPService::incomingData_ ()
{ 
  int_u1               buffer[8192];
  int_4                length = sizeof(buffer);
  int_u4               flags (0);   
  struct  sockaddr_in  client_addr;
  int_4                addrlen = sizeof(client_addr);
  int_4                NumBytes;
  try {
     recv()
     recvfrom() returns;  n > 0:  # bytes read
                          n = 0:  no msg/datagram avail (UNBLOCKED);
                                  we do NOT use UNBLOCKED reads though..
                                  or peer has done orderly shutdown (TCP only)
                          n < 0:  "something wicked this way comes..."
                                  sets errno; throws exception
        NumBytes = UDPSocketLib::UDP_recvFrom   (private_->socket_fd,
                                                 (unsigned char *)buffer, 
                                                 length, 
                                                 flags, 
                                                 &client_addr, 
                                                 addrlen);
        if (NumBytes > 0) {
          char  clientHost[64];
          int_4 len = sizeof(clientHost);
          UDPSocketLib::UDP_getHostByAddr (clientHost, len, &client_addr);
          string name (clientHost);
          log_.message("incomingData_::[UDP_recvFrom <clientAddr>]  NumBytes= " + 
                       Stringize(NumBytes) + ";  from <" + name + "(" + 
                       inet_ntoa(client_addr.sin_addr) + ")" + ":"+
                       Stringize(ntohs(client_addr.sin_port)) + ">");
        }
  } catch (const SocketLowLevelEx& e) {
      log_.error ("UDPService::[incomingData_]- Read error; "+e.problem());
    }
   No data...
  if (NumBytes == 0) {
    log_.message("UDPService::[incomingData_]- No Data");
    closeNetworkPort_();
  }
   ERROR- UDP socket read error
  else if (NumBytes < 0) {
    log_.error("UDPService::[incomingData_]- UDP socket read error; closing port...");
    closeNetworkPort_();
  }
  debugUDPOutput_ ((unsigned char *)buffer, NumBytes);
}
void UDPService :: incomingData_ ( ) { int_u1 buffer [ 8192 ] ; int_4 length = sizeof ( buffer ) ; int_u4 flags ( 0 ) ; struct sockaddr_in client_addr ; int_4 addrlen = sizeof ( client_addr ) ; int_4 NumBytes ; try { NumBytes = UDPSocketLib :: UDP_recvFrom ( private_ -> socket_fd , ( unsigned char * ) buffer , length , flags , & client_addr , addrlen ) ; if ( NumBytes > 0 ) { char clientHost [ 64 ] ; int_4 len = sizeof ( clientHost ) ; UDPSocketLib :: UDP_getHostByAddr ( clientHost , len , & client_addr ) ; string name ( clientHost ) ; log_ . message ( " " + Stringize ( NumBytes ) + " " + name + " " + inet_ntoa ( client_addr . sin_addr ) + " " + " " + Stringize ( ntohs ( client_addr . sin_port ) ) + " " ) ; } } catch ( const SocketLowLevelEx & e ) { log_ . error ( " " + e . problem ( ) ) ; } if ( NumBytes == 0 ) { log_ . message ( " " ) ; } else if ( NumBytes < 0 ) { log_ . error ( " " ) ; closeNetworkPort_ ( ) ; } debugUDPOutput_ ( ( unsigned char * ) buffer , NumBytes ) ; }
Preconditions:
Postconditions:
Preconditions : Postconditions :
// // recv() // recvfrom() returns;  n > 0:  # bytes read //                      n = 0:  no msg/datagram avail (UNBLOCKED); //                              we do NOT use UNBLOCKED reads though.. //                              or peer has done orderly shutdown (TCP only) //                      n < 0:  "something wicked this way comes..." //                              sets errno; throws exception // // // No data... // //closeNetworkPort_(); // // ERROR- UDP socket read error //