2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 // David Wagner <david.wagner@fokus.fraunhofer.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief UNProtocol non-inline non-template implementation */
24 #include "UNProtocol.hh"
25 //#include "UNProtocol.ih"
29 #include <sys/socket.h>
30 #include <sys/ioctl.h>
31 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
32 #include "../../../Utils/Exception.hh"
34 //#include "UNProtocol.mpp"
36 ///////////////////////////////cc.p////////////////////////////////////////
37 prefix_ unsigned senf::UNProtocol::available()
41 if (::ioctl(fd(),SIOCINQ,&n) < 0)
46 prefix_ bool senf::UNProtocol::eof()
52 prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address)
55 if(::connect(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
59 prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address)
62 if(::bind(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
69 prefix_ void senf::UNProtocol::close()
74 SocketProtocol::close();
77 prefix_ void senf::UNProtocol::terminate()
82 SocketProtocol::terminate();
85 prefix_ void senf::UNProtocol::check_and_unlink()
88 typedef ClientSocketHandle<MakeSocketPolicy<UNAddressingPolicy>::policy> UNSocketHandle;
90 UNSocketAddress una (static_socket_cast<UNSocketHandle>(fh()).local());
91 ::unlink(una.path().c_str());
93 catch (SystemException & e) {
97 // // struct sockaddr_un test;
99 // // memset( (char*)&test, 0xff, sizeof( test));
100 // // int fd = inputSocket.fd() ;
101 // //// printf( "fd: %d\n", fd);
103 // // int r = getsockname( fd, (struct sockaddr *)&test, &len);
105 // // perror( "bla:");
108 // // printf( "name: %d %d %s\n", r, len , test.sun_path);
109 // // unsigned char *p = (unsigned char*) &test;for( r=0; r< len; r++) printf( "%2.2x ", (int)(p[r])); printf ("\n");
111 // struct sockaddr_un test;
112 // socklen_t len = sizeof( test);
113 // int r = ::getsockname(fd(), (struct sockaddr *)&test, &len);
114 // if( r == 0 && ::strlen(test.sun_path) > 0){
115 // ::unlink( test.sun_path);
118 ///////////////////////////////cc.e////////////////////////////////////////
120 //#include "UNProtocol.mpp"
126 // comment-column: 40
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"