xrootd
XrdNetMsg.hh
Go to the documentation of this file.
00001 #ifndef __XRDNETMSG_H__
00002 #define __XRDNETMSG_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d N e t M s g . h h                           */
00006 /*                                                                            */
00007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #ifndef WIN32
00036 #include <strings.h>
00037 #include <unistd.h>
00038 #include <netinet/in.h>
00039 #include <sys/socket.h>
00040 #else
00041 #include <Winsock2.h>
00042 #endif
00043 
00044 class XrdSysError;
00045 
00046 class XrdNetMsg
00047 {
00048 public:
00049 
00050 // Send() sends a message to a host. If a destination is not supplied then the
00051 //        default destination at construction time is used.
00052 //        It returns one of three values:
00053 //        <0 -> Message not sent due to error (e.g., iovec data > 4096 bytes)
00054 //        =0 -> Message send (well as defined by UDP)
00055 //        >0 -> Message not sent, timeout occured.
00056 //
00057 int           Send(const char *buff,          // The data to be send
00058                          int   blen=0,        // Length (strlen(buff) if zero)
00059                    const char *dest=0,        // Hostname to send UDP datagram
00060                          int   tmo=-1);       // Timeout in ms (-1 = none)
00061 
00062 int           Send(const struct  iovec iov[], // Remaining parms as above
00063                          int     iovcnt,      // Number of elements in iovec
00064                    const char   *dest=0,      // Hostname to send UDP datagram
00065                          int     tmo=-1);     // Timeout in ms (-1 = none)
00066 
00067                 XrdNetMsg(XrdSysError *erp, const char *dest=0);
00068                ~XrdNetMsg() {if (DestHN) free(DestHN);
00069                              if (DestIP) free(DestIP);
00070                             }
00071 
00072 protected:
00073 int OK2Send(int timeout, const char *dest);
00074 int retErr(int ecode, const char *dest);
00075 
00076 XrdSysError       *eDest;
00077 char              *DestHN;
00078 struct sockaddr   *DestIP;
00079 int                DestSZ;
00080 int                FD;
00081 };
00082 #endif