ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
unix-fd.h
Go to the documentation of this file.
1 #ifndef UNIX_FD_H
2 #define UNIX_FD_H
3 
4 #include <sys/socket.h>
5 #include <sys/stat.h>
6 #include <time.h>
7 #include "ns3/object.h"
8 #include "wait-queue.h"
9 #include <list>
10 
11 namespace ns3 {
12 
13 class Waiter;
14 class DceManager;
15 
16 // This class heritate from Object for Dispose and Reference Counting features.
17 class UnixFd : public Object
18 {
19 public:
20  static TypeId GetTypeId (void);
21  virtual int Close (void) = 0;
22  virtual ssize_t Write (const void *buf, size_t count) = 0;
23  virtual ssize_t Read (void *buf, size_t count) = 0;
24  virtual ssize_t Recvmsg (struct msghdr *msg, int flags) = 0;
25  virtual ssize_t Sendmsg (const struct msghdr *msg, int flags) = 0;
26  virtual bool Isatty (void) const = 0;
27  virtual char * Ttyname (void);
28  virtual int Setsockopt (int level, int optname,
29  const void *optval, socklen_t optlen) = 0;
30  virtual int Getsockopt (int level, int optname,
31  void *optval, socklen_t *optlen) = 0;
32  virtual int Getsockname (struct sockaddr *name, socklen_t *namelen) = 0;
33  virtual int Getpeername (struct sockaddr *name, socklen_t *namelen) = 0;
34  virtual int Ioctl (int request, char *argp) = 0;
35  virtual int Bind (const struct sockaddr *my_addr, socklen_t addrlen) = 0;
36  virtual int Connect (const struct sockaddr *my_addr, socklen_t addrlen) = 0;
37  virtual int Listen (int backlog) = 0;
38  virtual int Shutdown (int how) = 0;
39  virtual int Accept (struct sockaddr *my_addr, socklen_t *addrlen) = 0;
40  virtual void * Mmap (void *start, size_t length, int prot, int flags, off64_t offset) = 0;
41  virtual off64_t Lseek (off64_t offset, int whence) = 0;
42  virtual int Fxstat (int ver, struct ::stat *buf) = 0;
43  virtual int Fxstat64 (int ver, struct ::stat64 *buf) = 0;
44  virtual int Fcntl (int cmd, unsigned long arg);
45  virtual int Settime (int flags,
46  const struct itimerspec *new_value,
47  struct itimerspec *old_value) = 0;
48  virtual int Gettime (struct itimerspec *cur_value) const = 0;
49  virtual int Ftruncate (off_t length) = 0;
50  virtual int GetRealFd (void) const;
51 
52  // Return true if a select on this fd should return POLLHUP
53  virtual bool HangupReceived (void) const = 0;
54 
55  virtual int Poll (PollTable* ptable) = 0;
56 
57  void IncFdCount (void);
58  void DecFdCount (void);
59  int GetFdCount (void) const;
60 
61  friend class PollTableEntry;
62  friend class PollTable;
63  friend class DceManager;
64 protected:
65  UnixFd ();
66  void RemoveWaitQueue (WaitQueueEntry*, bool andUnregister);
67  void AddWaitQueue (WaitQueueEntry*, bool andRegister);
68  void WakeWaiters (void *key);
69  int m_fdFlags;
71 
72 private:
73  std::list <WaitQueueEntry*> m_waitQueueList;
74  // Number of FD referencing me
75  int m_fdCount;
76 };
77 
78 } // namespace ns3
79 
80 #endif /* UNIX_FD_H */