XRootD
Loading...
Searching...
No Matches
XrdCmsTalk.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d C m s T a l k . c c */
4/* */
5/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <sys/types.h>
32#include <netinet/in.h>
33#include <cinttypes>
34
36
37#include "Xrd/XrdLink.hh"
38#include "XrdCms/XrdCmsTalk.hh"
39
40using namespace XrdCms;
41
42/******************************************************************************/
43/* A t t e n d */
44/******************************************************************************/
45
47 char *buff, int blen,
48 int &rlen, int TimeOut)
49{
50
51// First obtain the complete header
52//
53 if (Link->Recv((char *)&Hdr, sizeof(Hdr), TimeOut) != sizeof(Hdr))
54 return "header not sent";
55
56// Decode the length and make sure it fits in the buffer
57//
58 rlen = static_cast<int>(ntohs(Hdr.datalen));
59 if (rlen > blen) return "data too long";
60
61// Get the actual data
62//
63 if (Link->Recv(buff,rlen,TimeOut) != rlen) return "data not received";
64
65// All done
66//
67 return 0;
68}
69
70/******************************************************************************/
71/* C o m p l a i n */
72/******************************************************************************/
73
74int XrdCmsTalk::Complain(XrdLink *Link, int ecode, const char *msg)
75{
76 static const int xNum = 2;
77
78 struct iovec Liov[xNum];
79 int mlen = strlen(msg)+1;
80 CmsResponse LEResp={{0, kYR_error, 0, 0}, htonl((unsigned int)ecode)};
81
82// Fill out header and iovector
83//
84 LEResp.Hdr.datalen = htons(static_cast<kXR_unt16>(mlen+sizeof(LEResp.Val)));
85 Liov[0].iov_base = (char *)&LEResp;
86 Liov[0].iov_len = sizeof(LEResp);
87 Liov[1].iov_base = (char *)msg;
88 Liov[1].iov_len = mlen;
89
90// Send off the data
91//
92 Link->Send(Liov, xNum);
93 return 0;
94}
95
96/******************************************************************************/
97/* R e q u e s t */
98/******************************************************************************/
99
101 char *buff, int blen)
102{
103 struct iovec ioV[2] = {{(char *)&Hdr, sizeof(Hdr)},
104 {(char *)buff, (size_t)blen}};
105
106 Hdr.datalen = htons(static_cast<unsigned short>(blen));
107
108// Send the actual data
109//
110 if (Link->Send(ioV, 2) < 0) return "request not sent";
111 return 0;
112}
113
114/******************************************************************************/
115/* R e s p o n d */
116/******************************************************************************/
117
119 char *buff, int blen)
120{
121 static const unsigned short ovhd = sizeof(kXR_unt32);
122 CmsResponse Resp = {{0, (kXR_char)rcode, 0,
123 htons(static_cast<unsigned short>(blen+ovhd))}, 0};
124 struct iovec ioV[2] = {{(char *)&Resp, sizeof(Resp)},
125 { buff, (size_t)blen}};
126
127// Send the actual data
128//
129 if (Link->Send(ioV, 2) < 0) return "response not sent";
130 return 0;
131}
unsigned int kXR_unt32
Definition XPtypes.hh:90
unsigned short kXR_unt16
Definition XPtypes.hh:67
unsigned char kXR_char
Definition XPtypes.hh:65
static const char * Attend(XrdLink *Link, XrdCms::CmsRRHdr &Hdr, char *buff, int blen, int &rlen, int tmo=5000)
Definition XrdCmsTalk.cc:46
static const char * Respond(XrdLink *Link, XrdCms::CmsRspCode rcode, char *buff, int blen)
static const char * Request(XrdLink *Link, XrdCms::CmsRRHdr &Hdr, char *buff, int blen)
static int Complain(XrdLink *Link, int ecode, const char *msg)
Definition XrdCmsTalk.cc:74
kXR_unt16 datalen
Definition YProtocol.hh:86
@ kYR_error
Definition YProtocol.hh:142