XrdCmsTalk.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                         X r d C m s T a l k . c c                          */
00004 /*                                                                            */
00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //          $Id: XrdCmsTalk.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 const char *XrdCmsTalkCVSID = "$Id: XrdCmsTalk.cc 24468 2008-06-22 16:47:03Z ganis $";
00014  
00015 #include <sys/types.h>
00016 #include <netinet/in.h>
00017 #include <inttypes.h>
00018 
00019 #include "XProtocol/YProtocol.hh"
00020 
00021 #include "Xrd/XrdLink.hh"
00022 #include "XrdCms/XrdCmsTalk.hh"
00023 
00024 using namespace XrdCms;
00025 
00026 /******************************************************************************/
00027 /*                                A t t e n d                                 */
00028 /******************************************************************************/
00029 
00030 const char *XrdCmsTalk::Attend(XrdLink *Link, XrdCms::CmsRRHdr &Hdr,
00031                                char    *buff, int blen,
00032                                int     &rlen, int TimeOut)
00033 {
00034 
00035 // First obtain the complete header
00036 //
00037    if (Link->Recv((char *)&Hdr, sizeof(Hdr), TimeOut) != sizeof(Hdr))
00038       return "header not sent";
00039 
00040 // Decode the length and make sure it fits in the buffer
00041 //
00042    rlen = static_cast<int>(ntohs(Hdr.datalen));
00043    if (rlen > blen) return "data too long";
00044 
00045 // Get the actual data
00046 //
00047    if (Link->Recv(buff,rlen,TimeOut) != rlen) return "data not received";
00048 
00049 // All done
00050 //
00051    return 0;
00052 }
00053 
00054 /******************************************************************************/
00055 /*                              C o m p l a i n                               */
00056 /******************************************************************************/
00057 
00058 int XrdCmsTalk::Complain(XrdLink *Link, int ecode, const char *msg)
00059 {
00060    static const int xNum   = 2;
00061 
00062    struct iovec Liov[xNum];
00063    int mlen = strlen(msg)+1;
00064    CmsResponse LEResp={{0, kYR_error, 0, 0}, htonl(ecode)};
00065 
00066 // Fill out header and iovector
00067 //
00068    LEResp.Hdr.datalen = htons(static_cast<kXR_unt16>(mlen+sizeof(LEResp.Val)));
00069    Liov[0].iov_base = (char *)&LEResp;
00070    Liov[0].iov_len  = sizeof(LEResp);
00071    Liov[1].iov_base = (char *)msg;
00072    Liov[1].iov_len  = mlen;
00073 
00074 // Send off the data
00075 //
00076    Link->Send(Liov, xNum);
00077    return 0;
00078 }
00079   
00080 /******************************************************************************/
00081 /*                               R e q u e s t                                */
00082 /******************************************************************************/
00083   
00084 const char *XrdCmsTalk::Request(XrdLink *Link, XrdCms::CmsRRHdr &Hdr,
00085                                 char    *buff, int blen)
00086 {
00087    struct iovec ioV[2] = {{(char *)&Hdr, sizeof(Hdr)},
00088                           {(char *)buff, blen}};
00089 
00090    Hdr.datalen = htons(static_cast<unsigned short>(blen));
00091 
00092 // Send the actual data
00093 //
00094    if (Link->Send(ioV, 2) < 0) return "request not sent";
00095    return 0;
00096 }
00097 
00098 /******************************************************************************/
00099 /*                               R e s p o n d                                */
00100 /******************************************************************************/
00101 
00102 const char *XrdCmsTalk::Respond(XrdLink *Link, XrdCms::CmsRspCode rcode,
00103                                 char    *buff, int                blen)
00104 {
00105    static const unsigned short ovhd = sizeof(kXR_unt32);
00106    CmsResponse Resp = {{0, rcode, 0,
00107                         htons(static_cast<unsigned short>(blen+ovhd))}, 0};
00108    struct iovec ioV[2] = {{(char *)&Resp, sizeof(Resp)},
00109                           {         buff, blen}};
00110 
00111 // Send the actual data
00112 //
00113    if (Link->Send(ioV, 2) < 0) return "response not sent";
00114    return 0;
00115 }

Generated on Tue Jul 5 14:46:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1