ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
local-stream-socket-fd.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Frederic Urbani <frederic.urbani@inria.fr>
19  *
20  */
21 #ifndef LOCAL_STREAM_SOCKET_FD_H
22 #define LOCAL_STREAM_SOCKET_FD_H
23 
24 #include "unix-fd.h"
25 #include "ns3/ptr.h"
26 #include <list>
27 #include "ns3/nstime.h"
28 #include "ns3/object.h"
29 #include "local-socket-fd.h"
30 #include "wait-queue.h"
31 
32 namespace ns3 {
33 
34 class Waiter;
35 
44 class LocalSocketFdFactory;
45 class WaitQueueEntryTimeout;
46 
47 #define LOCAL_SOCKET_MAX_BUFFER 1024 * 128
48 
50 {
51 public:
52  static TypeId GetTypeId (void);
53  virtual TypeId GetInstanceTypeId (void) const;
54 
55  LocalStreamSocketFd (Ptr<LocalSocketFdFactory> f);
56  LocalStreamSocketFd (LocalStreamSocketFd *peer, std::string connectPath);
57 
58  virtual ~LocalStreamSocketFd ();
59 
60  virtual void DoDispose (void);
61 
62  virtual int Close (void);
63  virtual ssize_t Write (const void *buf, size_t count);
64  virtual ssize_t Read (void *buf, size_t count);
65  virtual ssize_t Recvmsg (struct msghdr *msg, int flags);
66  virtual ssize_t Sendmsg (const struct msghdr *msg, int flags);
67  virtual bool Isatty (void) const;
68  virtual int Setsockopt (int level, int optname,
69  const void *optval, socklen_t optlen);
70  virtual int Getsockopt (int level, int optname,
71  void *optval, socklen_t *optlen);
72  virtual int Getsockname (struct sockaddr *name, socklen_t *namelen);
73  virtual int Getpeername (struct sockaddr *name, socklen_t *namelen);
74  virtual int Bind (const struct sockaddr *my_addr, socklen_t addrlen);
75  virtual int Connect (const struct sockaddr *my_addr, socklen_t addrlen);
76  virtual int Listen (int backlog);
77  virtual int Shutdown (int how);
78  virtual int Accept (struct sockaddr *my_addr, socklen_t *addrlen);
79 
80  virtual bool CanRecv (void) const;
81  virtual bool CanSend (void) const;
82  virtual bool HangupReceived (void) const;
83 
84  virtual int Poll (PollTable* ptable);
85 
86 protected:
87  virtual void ClearAll (bool andWakeUp);
88  virtual bool IsClosed (void) const;
89 
90 private:
91  bool InternalConnect (void);
92  bool IsAccepting (void);
93  bool IsListening (void);
96  void SetPeer (LocalStreamSocketFd *sock);
97  void PeerClosed (void);
98  bool IsShutWrite (void) const;
99 
100  enum State
101  {
110  };
111  typedef std::list<LocalStreamSocketFd*> FifoCnx;
112 
117 
118 };
119 
120 } // namespace ns3
121 
122 #endif /* LOCAL_STREAM_SOCKET_FD_H */