MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
usesock.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/usesock.h,v 1.20 2017/01/12 14:46:11 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #ifndef USESOCK_H
33 #define USESOCK_H
34 #ifdef USE_SOCKET
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <sys/un.h>
38 
39 class UseSocket {
40 protected:
41  int sock;
42  int socket_type;
43  bool create;
44  bool connected;
45  bool abandoned;
46 
47  mutable socklen_t socklen;
48 
49  void PostConnect(void);
50 
51 public:
52  UseSocket(bool c);
53  UseSocket(int t, bool c);
54  virtual ~UseSocket(void);
55 
56  virtual std::ostream& Restart(std::ostream& out) const;
57 
58  int GetSock(void) const;
59  void SetSock(int s);
60  virtual void Connect(void);
61  virtual void ConnectSock(int s);
62  bool Create(void) const;
63  bool Connected(void) const;
64  void Abandon(void);
65  bool Abandoned(void) const;
66 
67  socklen_t& GetSocklen(void) const;
68  virtual struct sockaddr *GetSockaddr(void) const = 0;
69 
70  ssize_t send(const void *buf, size_t len, int flags);
71  ssize_t recv(void *buf, size_t len, int flags);
72 };
73 
74 class UseInetSocket : public UseSocket {
75 protected:
76  std::string host;
77  unsigned short int port;
78  struct sockaddr_in addr;
79 
80  void UseInetSocket_int(void);
81 
82 public:
83  UseInetSocket(const std::string& h, unsigned short p, bool c);
84  UseInetSocket(const std::string& h, unsigned short p, int t, bool c);
85  virtual ~UseInetSocket(void);
86 
87  std::ostream& Restart(std::ostream& out) const;
88 
89  void Connect(void);
90  void ConnectSock(int s);
91  struct sockaddr *GetSockaddr(void) const;
92 };
93 
94 class UseLocalSocket : public UseSocket {
95 protected:
96  std::string path;
97  struct sockaddr_un addr;
98 
99  void UseLocalSocket_int(void);
100 
101 public:
102  UseLocalSocket(const std::string& p, bool c);
103  UseLocalSocket(const std::string& p, int t, bool c);
104  virtual ~UseLocalSocket(void);
105 
106  std::ostream& Restart(std::ostream& out) const;
107 
108  void Connect(void);
109  void ConnectSock(int s);
110  struct sockaddr *GetSockaddr(void) const;
111 };
112 #endif
113 #endif /* USESOCK_H */
114 
const char * host
Definition: autopilot.c:142
static std::stack< cleanup * > c
Definition: cleanup.cc:59
unsigned short int port
Definition: autopilot.c:143
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
const char * path
Definition: autopilot.c:141