21 |
#ifndef MONIT_SOCKET_H |
#ifndef MONIT_SOCKET_H |
22 |
#define MONIT_SOCKET_H |
#define MONIT_SOCKET_H |
23 |
|
|
24 |
|
#define SOCKET_TCP 1 |
25 |
|
#define SOCKET_UDP 2 |
26 |
|
|
27 |
|
|
28 |
/** |
/** |
29 |
* This class implements a <b>Socket</b>. A socket is an endpoint for |
* This class implements a <b>Socket</b>. A socket is an endpoint for |
40 |
|
|
41 |
/** |
/** |
42 |
* Create a new Socket opened against host:port. The returned Socket |
* Create a new Socket opened against host:port. The returned Socket |
43 |
* is a connected socket. If the use_ssl parameter is TRUE the socket |
* is a connected socket. This method can be used to create either TCP |
44 |
* is created using SSL. |
* or UDP sockets and the type parameter is used to select the socket |
45 |
|
* type. If the use_ssl parameter is TRUE the socket is created using |
46 |
|
* SSL. Only TCP sockets may use SSL. |
47 |
* @param host The remote host to open the Socket against. The host |
* @param host The remote host to open the Socket against. The host |
48 |
* may be a hostname found in the DNS or an IP address string. |
* may be a hostname found in the DNS or an IP address string. |
49 |
* @param port The port number to connect to |
* @param port The port number to connect to |
50 |
* @param protocol The socket protocol to use (SOCK_STREAM or SOCK_DGRAM) |
* @param type The socket type to use (SOCKET_TCP or SOCKET_UPD) |
51 |
* @param use_ssl if TRUE the socket is created supporting SSL |
* @param use_ssl if TRUE the socket is created supporting SSL |
52 |
* @return The connected Socket or NULL if an error occurred |
* @return The connected Socket or NULL if an error occurred |
53 |
*/ |
*/ |
54 |
Socket_T socket_new(char *host, int port, int protocol, int use_ssl); |
Socket_T socket_new(char *host, int port, int type, int use_ssl); |
55 |
|
|
56 |
|
|
57 |
|
/** |
58 |
|
* Factory method for creating a new Socket from a monit Port object |
59 |
|
* @param port The port object to create a socket from |
60 |
|
* @return The connected Socket or NULL if an error occurred |
61 |
|
*/ |
62 |
|
Socket_T socket_create(void *port); |
63 |
|
|
64 |
|
|
65 |
/** |
/** |
66 |
* Destroy a Socket object. Close the socket and release allocated |
* Destroy a Socket object. Close the socket and release allocated |
67 |
* resources. |
* resources. |
68 |
* @param S A Socket object reference |
* @param S A Socket object reference |
69 |
*/ |
*/ |
70 |
void socket_free(Socket_T *S); |
void socket_free(Socket_T *S); |
71 |
|
|
72 |
|
|
73 |
/** |
/** |
74 |
|
* Returns TRUE if the socket is ready for i|o |
75 |
|
* @param S A Socket object reference |
76 |
|
* @return TRUE if the socket is ready otherwise FALSE |
77 |
|
*/ |
78 |
|
int socket_is_ready(Socket_T s); |
79 |
|
|
80 |
|
|
81 |
|
/** |
82 |
|
* Get the underlying socket descriptor |
83 |
|
* @param s A Socket object |
84 |
|
* @return The socket descriptor |
85 |
|
*/ |
86 |
|
int socket_get_socket(Socket_T s); |
87 |
|
|
88 |
|
|
89 |
|
/** |
90 |
|
* Get the remote port number the socket is connected to |
91 |
|
* @param s A Socket object |
92 |
|
* @return The remote host's port number |
93 |
|
*/ |
94 |
|
int socket_get_remote_port(Socket_T s); |
95 |
|
|
96 |
|
|
97 |
|
/** |
98 |
|
* Get the remote host name this socket is connected to |
99 |
|
* @param s A Socket object |
100 |
|
* @return The remote hostname |
101 |
|
*/ |
102 |
|
const char *Socket_get_remote_hostname(Socket_T s); |
103 |
|
|
104 |
|
|
105 |
|
/** |
106 |
* Writes a character string. Use this function to send text based |
* Writes a character string. Use this function to send text based |
107 |
* messages to a client. |
* messages to a client. |
108 |
* @param s A Socket_T object |
* @param s A Socket_T object |