/home/vlg/develop/libASSA/libassa/assa/UnConUDPSocket.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                         UnConUDPSocket.C
00004 //------------------------------------------------------------------------------
00005 //  Copyright (c) 1999 by Vladislav Grinchenko
00006 //
00007 //  This library is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU Library General Public
00009 //  License as published by the Free Software Foundation; either
00010 //  version 2 of the License, or (at your option) any later version.
00011 //------------------------------------------------------------------------------
00012 //  Created: 03/23/99
00013 //------------------------------------------------------------------------------
00014 
00015 #include "assa/UnConUDPSocket.h"
00016 
00017 #if defined (WIN32)
00018 typedef unsigned int socklen_t;
00019 #endif
00020 
00021 using namespace ASSA;
00022 
00023 int 
00024 UnConUDPSocket::
00025 recvfrom (char* buf_, int size_, Address* peer_addr_)
00026 {
00027     // ::recvfrom() can return 0 bytes which is not 
00028     // considered an eof. Peer can advertise its address to 
00029     // the server by sending 0 bytes length message.
00030     //
00031 
00032     // char self[] = "Socket::recvfro"; trace(self);
00033 
00034     // Setting saddr_len is crucial to proper ::recvfrom() operation.
00035     // If left improprely initialized, ::recvfrom() won't fill in peer's 
00036     // address and won't report an error either. If SA ptr is passed to 
00037     // recvfrom() along with uninitialized address len (or set to 0), 
00038     // recvfrom() returns zeroed out address structure!!!
00039 
00040     int len;
00041     socklen_t pa_len = peer_addr_->getLength();
00042 
00043     SA* pa = peer_addr_->getAddress();
00044 
00045 #if defined (__CYGWIN32__) || defined (WIN32)
00046     len = ::recvfrom(getHandler(), buf_, size_, 0, pa, (int*)&pa_len);
00047 #else  // posix/unix
00048     len = ::recvfrom(getHandler(), buf_, size_, 0, pa, &pa_len);
00049 #endif
00050 
00051     // Q: for UNIX domain socket, returned length will be essential to
00052     // remember and probably should be set in peer_addr_ by calling
00053     // setLength().....
00054     
00055     return len;
00056 }
00057 
00058 int 
00059 UnConUDPSocket::
00060 sendto (const char* buf_, const unsigned int size_, const Address* peer_addr_)
00061 {
00062     return  ::sendto (getHandler(), buf_, size_, 0,
00063              peer_addr_->getAddress(),
00064              peer_addr_->getLength());
00065 }
00066 
00067 

Generated on Sun Aug 13 15:08:00 2006 for libassa by  doxygen 1.4.6