ConUDPSocket.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------
00003 //                              ConUDPSocket.cpp
00004 //------------------------------------------------------------------------------
00005 //  Copyright (C) 1999  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 
00013 #include "assa/ConUDPSocket.h"
00014 #include "assa/UNIXAddress.h"
00015 #include "assa/INETAddress.h"
00016 
00017 using namespace ASSA;
00018 
00019 bool
00020 ConUDPSocket::
00021 connect (const Address& peer_address_)
00022 {
00023     char self[] = "ConUDPSocket::connect"; trace(self);
00024 
00025     if ( ::connect (getHandler(),peer_address_.getAddress(),
00026                     peer_address_.getLength()) < 0 ) {
00027         setstate (Socket::failbit);
00028         return false;
00029     }
00030     return true;
00031 }
00032 
00033 void
00034 ConUDPSocket::
00035 unconnect()
00036 {
00037     // Ignore errors here. On some systems connect() might return
00038     // EAFNOSUPPORT error, on some might not, but it is OK.
00039     //
00040     char self[] = "ConUDPSocket::unconnect"; trace(self);
00041 
00042     if ( getDomain() == AF_INET ) {
00043         INETAddress addr;
00044         SA_IN* addrp = (SA_IN*) addr.getAddress();
00045 
00046         addrp->sin_family = AF_UNSPEC;
00047         (void) connect(addr);
00048     }
00049     else {          // AF_LOCAL
00050         // I haven't tested whether it works at all.
00051         
00052         UNIXAddress addr("");
00053         SA_UN* addrp = (SA_UN*) addr.getAddress();
00054 
00055         addrp->sun_family = AF_UNSPEC;
00056         (void) connect(addr);       
00057     }
00058 }
00059 
00060 int
00061 ConUDPSocket::
00062 read(char* packet_, const unsigned int size_)
00063 {
00064     int len;
00065     len = ::read(getHandler(), packet_, size_);
00066 
00067     if (len == -1) {
00068         setstate (Socket::failbit);
00069     }
00070     else if ( len == 0 ) {
00071         setstate (Socket::failbit | Socket::eofbit);
00072     }
00073     return len;
00074 }
00075 
00076 int
00077 ConUDPSocket::
00078 write (const char* packet_, const unsigned int size_)
00079 {
00080     return  ::write(getHandler(), (const void*) packet_, size_);
00081 }
00082 

Generated on Mon Dec 19 16:37:14 2005 for libassa by  doxygen 1.4.5