libutil++  1.9.3
 All Classes Functions Variables
SocketPair.cpp
1 /*
2 ** libutil++
3 ** $Id: SocketPair.cpp 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 static const char rcsid[] __attribute__((used)) = "$Id: SocketPair.cpp 1653 2016-02-28 19:54:59Z sella $";
10 
11 #include "SocketPair.h"
12 
13 #include <unistd.h>
14 
15 using namespace sella::net;
16 
17 SocketPair::SocketPair() throw (SocketException) {
18  int fd[2];
19 
20  if (::socketpair(AF_UNIX, SOCK_STREAM, 0, fd) != 0) {
21  THROW2(SocketException, "socketpair()");
22  }
23 
24  first = UnixSocket::shared_ptr(fd[0]);
25  second = UnixSocket::shared_ptr(fd[1]);
26 }
27 
28 SocketPair::~SocketPair() {
29 }
30 
31 UnixSocket::shared SocketPair::getFirst(void) {
32  return first;
33 }
34 
35 UnixSocket::shared SocketPair::getSecond(void) {
36  return second;
37 }
38 
39 const SocketPair::shared SocketPair::shared_ptr() throw (SocketException) {
40  return std::make_shared<SocketPair>();
41 }
42 
43 /*
44 ** vim: noet ts=3 sw=3
45 */