deps/PicklingTools170Release/M2k/udpif/udpservice.cc
int_4 UDPService::writeTo (const void*         buf, 
                           const int_4         bytes,
                           struct sockaddr_in* clientAddr, 
                           const int_4         clientAddrLength)
{ 
  int_u4               flags (0);   
  int_4                NumBytes = -1;

    try {
      //
      // sendTo()   returns;  n > 0:  # bytes read
      //                      n = 0:  no data written; EWOULDBLOCK or EAGAIN
      //                              from NONBLOCK socket setting, maybe..
      //                      n < 0:  "something wicked this way comes..."
      //                              sets errno
      //
      NumBytes = UDPSocketLib::UDP_sendTo (private_->socket_fd,
                                           (unsigned char *)buf, 
                                           bytes, 
                                           flags, 
                                           clientAddr, 
                                           clientAddrLength);

    } catch (const SocketLowLevelEx& e) {
        char  clientHost[64];
        int_4 len = sizeof(clientHost);
        UDPSocketLib::UDP_getHostByAddr (clientHost, len, clientAddr);
        string name (clientHost);
        log_.error ("UDPService::[writeTo]- Failed UDP write to <" + 
                    name + " (" +
                    inet_ntoa(clientAddr->sin_addr) + "):"+
                    Stringize(ntohs(clientAddr->sin_port)) + ">");
        log_.error ("UDPService::[writeTo]- " + e.problem());
      }

    return NumBytes;

}
//
// Preconditions: 
//
// Postconditions:
//
// Parameters:
//   const void*         buf              IN;  buffer of data to send
//   const int_4         bytes            IN;  number bytes in buf to send
//   struct sockaddr_in* clientAddr,      IN;  destination address   
//   const int_4         clientAddrLength IN;  length of dest address struct
//
// Description:
//   Send data in buf over network using UDP from Host:Port to
//   destination defined by clientAddr
//
//


const void*         buf              IN;  buffer of data to send
const int_4         bytes            IN;  number bytes in buf to send
struct sockaddr_in* clientAddr,      IN;  destination address
const int_4         clientAddrLength IN;  length of dest address struct

Send data in buf over network using UDP from Host:Port to
destination defined by clientAddr
const void * buf IN ; buffer of data to send const int_4 bytes IN ; number bytes in buf to send struct sockaddr_in * clientAddr IN ; destination address const int_4 clientAddrLength IN ; length of dest address struct Send data in buf over network using UDP from Host : Port to destination defined by clientAddr
int_4 UDPService::writeTo (const void*         buf, 
                           const int_4         bytes,
                           struct sockaddr_in* clientAddr, 
                           const int_4         clientAddrLength)
{ 
  int_u4               flags (0);   
  int_4                NumBytes = -1;
    try {
       sendTo()   returns;  n > 0:  # bytes read
                            n = 0:  no data written; EWOULDBLOCK or EAGAIN
                                    from NONBLOCK socket setting, maybe..
                            n < 0:  "something wicked this way comes..."
                                    sets errno
      NumBytes = UDPSocketLib::UDP_sendTo (private_->socket_fd,
                                           (unsigned char *)buf, 
                                           bytes, 
                                           flags, 
                                           clientAddr, 
                                           clientAddrLength);
    } catch (const SocketLowLevelEx& e) {
        char  clientHost[64];
        int_4 len = sizeof(clientHost);
        UDPSocketLib::UDP_getHostByAddr (clientHost, len, clientAddr);
        string name (clientHost);
        log_.error ("UDPService::[writeTo]- Failed UDP write to <" + 
                    name + " (" +
                    inet_ntoa(clientAddr->sin_addr) + "):"+
                    Stringize(ntohs(clientAddr->sin_port)) + ">");
        log_.error ("UDPService::[writeTo]- " + e.problem());
      }
    return NumBytes;
}
int_4 UDPService :: writeTo ( const void * buf , const int_4 bytes , struct sockaddr_in * clientAddr , const int_4 clientAddrLength ) { int_u4 flags ( 0 ) ; int_4 NumBytes = -1 ; try { NumBytes = UDPSocketLib :: UDP_sendTo ( private_ -> socket_fd , ( unsigned char * ) buf , bytes , flags , clientAddr , clientAddrLength ) ; } catch ( const SocketLowLevelEx & e ) { char clientHost [ 64 ] ; int_4 len = sizeof ( clientHost ) ; UDPSocketLib :: UDP_getHostByAddr ( clientHost , len , clientAddr ) ; string name ( clientHost ) ; log_ . error ( " " + name + " " + inet_ntoa ( clientAddr -> sin_addr ) + " " + Stringize ( ntohs ( clientAddr -> sin_port ) ) + " " ) ; log_ . error ( " " + e . problem ( ) ) ; } return NumBytes ; }
Preconditions:
Postconditions:
Preconditions : Postconditions :
// // sendTo()   returns;  n > 0:  # bytes read //                      n = 0:  no data written; EWOULDBLOCK or EAGAIN //                              from NONBLOCK socket setting, maybe.. //                      n < 0:  "something wicked this way comes..." //                              sets errno //