BSDAddressingPolicy.cc

Go to the documentation of this file.
00001 // $Id: BSDAddressingPolicy.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00027 #include "BSDAddressingPolicy.hh"
00028 //#include "BSDAddressingPolicy.ih"
00029 
00030 // Custom includes
00031 #include <sys/socket.h>
00032 #include <sys/types.h>
00033 #include <senf/Utils/Exception.hh>
00034 
00035 //#include "BSDAddressingPolicy.mpp"
00036 #define prefix_
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 prefix_ void senf::BSDAddressingPolicyMixinBase::do_local(FileHandle const & handle,
00040                                                                  struct sockaddr * addr,
00041                                                                  socklen_t * len)
00042 {
00043     if (::getsockname(handle.fd(),addr,len) < 0)
00044         SENF_THROW_SYSTEM_EXCEPTION("");
00045 }
00046 
00047 prefix_ void senf::BSDAddressingPolicyMixinBase::do_peer(FileHandle const & handle,
00048                                                                 struct sockaddr * addr,
00049                                                                 socklen_t * len)
00050 {
00051     if (::getpeername(handle.fd(),addr,len) < 0)
00052         SENF_THROW_SYSTEM_EXCEPTION("");
00053 }
00054 
00055 prefix_ void senf::BSDAddressingPolicyMixinBase::do_bind(FileHandle const & handle,
00056                                                                 struct sockaddr const * addr,
00057                                                                 socklen_t len)
00058 {
00059     if (::bind(handle.fd(),addr,len) < 0)
00060         SENF_THROW_SYSTEM_EXCEPTION("");
00061 }
00062 
00063 prefix_ void senf::BSDAddressingPolicyMixinBase::do_connect(FileHandle const & handle,
00064                                                                    struct sockaddr const * addr,
00065                                                                    socklen_t len)
00066 {
00067     while(1) {
00068         if (::connect(handle.fd(),addr,len) < 0)
00069             switch (errno) {
00070             case EINPROGRESS: {
00071                 handle.waitWriteable();
00072                 int err = 0;
00073                 socklen_t len = sizeof(err);
00074                 if (::getsockopt(handle.fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
00075                     SENF_THROW_SYSTEM_EXCEPTION("");
00076                 if (err != 0)
00077                     throw SystemException(err SENF_EXC_DEBUGINFO);
00078                 return;
00079             }
00080             case EINTR:
00081                 break;
00082             default:
00083                 SENF_THROW_SYSTEM_EXCEPTION("");
00084             }
00085         else
00086             return;
00087     }
00088 }
00089 
00090 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00091 #undef prefix_
00092 //#include "BSDAddressingPolicy.mpp"
00093 
00094 
00095 // Local Variables:
00096 // mode: c++
00097 // fill-column: 100
00098 // c-file-style: "senf"
00099 // indent-tabs-mode: nil
00100 // ispell-local-dictionary: "american"
00101 // compile-command: "scons -u test"
00102 // comment-column: 40
00103 // End: