xrootd
XrdNetMsg.hh
Go to the documentation of this file.
1 #ifndef __XRDNETMSG_H__
2 #define __XRDNETMSG_H__
3 /******************************************************************************/
4 /* */
5 /* X r d N e t M s g . h h */
6 /* */
7 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #include <stdlib.h>
16 #include <string.h>
17 #ifndef WIN32
18 #include <strings.h>
19 #include <unistd.h>
20 #include <netinet/in.h>
21 #include <sys/socket.h>
22 #else
23 #include <Winsock2.h>
24 #endif
25 
26 class XrdSysError;
27 
28 class XrdNetMsg
29 {
30 public:
31 
32 // Send() sends a message to a host. If a destination is not supplied then the
33 // default destination at construction time is used.
34 // It returns one of three values:
35 // <0 -> Message not sent due to error (e.g., iovec data > 4096 bytes)
36 // =0 -> Message send (well as defined by UDP)
37 // >0 -> Message not sent, timeout occured.
38 //
39 int Send(const char *buff, // The data to be send
40  int blen=0, // Length (strlen(buff) if zero)
41  const char *dest=0, // Hostname to send UDP datagram
42  int tmo=-1); // Timeout in ms (-1 = none)
43 
44 int Send(const struct iovec iov[], // Remaining parms as above
45  int iovcnt, // Number of elements in iovec
46  const char *dest=0, // Hostname to send UDP datagram
47  int tmo=-1); // Timeout in ms (-1 = none)
48 
49  XrdNetMsg(XrdSysError *erp, const char *dest=0);
50  ~XrdNetMsg() {if (DestHN) free(DestHN);
51  if (DestIP) free(DestIP);
52  }
53 
54 protected:
55 int OK2Send(int timeout, const char *dest);
56 int retErr(int ecode, const char *dest);
57 
59 char *DestHN;
60 struct sockaddr *DestIP;
61 int DestSZ;
62 int FD;
63 };
64 #endif