24# include <netinet/in.h>
37#define XPRNOTIFY(m,e) \
39 TRACET(TraceID(), XERR, m << ": " << e); \
42 if (e.length() > 0) { \
43 TRACET(TraceID(), RSP, m << " (" << e <<")"); \
45 TRACET(TraceID(), RSP, m); \
50#define XPRTRACING(a) ((a != 0) || (TRACING(RSP)))
53 { XrdSysMutexHelper mh(fMutex); \
55 TRACE(XERR, "link is undefined! "); \
57 } else if (fLink->FDnum() < 0) { \
58 TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")"); \
62#define CHECKLINKNOMTX \
64 TRACE(XERR, "link is undefined! "); \
66 } else if (fLink->FDnum() < 0) { \
67 TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")"); \
76 XPDLOC(RSP,
"Response::Send:1")
81 XrdOucString tmsg, emsg;
82 ServerResponseHeader resp;
84 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
87 rc =
LinkSend((
char *)&resp,
sizeof(resp), emsg);
98 XPDLOC(RSP,
"Response::Send:2")
103 XrdOucString tmsg, emsg;
104 ServerResponseHeader resp;
106 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
109 rc =
LinkSend((
char *)&resp,
sizeof(resp), emsg);
121 XPDLOC(RSP,
"Response::Send:3")
126 XrdOucString tmsg, emsg;
127 ServerResponseHeader resp;
129 struct iovec respIO[2];
130 respIO[0].iov_base = (caddr_t)&resp;
131 respIO[0].iov_len =
sizeof(resp);
132 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
133 respIO[1].iov_base = (caddr_t)msg;
134 respIO[1].iov_len = strlen(msg)+1;
135 resp.dlen =
static_cast<kXR_int32
>(htonl(respIO[1].iov_len));
137 rc =
LinkSend(respIO, 2,
sizeof(resp) + respIO[1].iov_len, emsg);
149 XPDLOC(RSP,
"Response::Send:4")
154 XrdOucString tmsg, emsg;
155 ServerResponseHeader resp;
157 struct iovec respIO[2];
158 respIO[0].iov_base = (caddr_t)&resp;
159 respIO[0].iov_len =
sizeof(resp);
160 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
161 respIO[1].iov_base = (caddr_t)data;
162 respIO[1].iov_len = dlen;
163 resp.dlen =
static_cast<kXR_int32
>(htonl(dlen));
165 rc =
LinkSend(respIO, 2,
sizeof(resp) + dlen, emsg);
167 if (
XPRTRACING(rc))
XPDFORM(tmsg,
"sending %d data bytes; status=%d", dlen, rcode);
177 XPDLOC(RSP,
"Response::Send:5")
182 XrdOucString tmsg, emsg;
183 ServerResponseHeader resp;
185 struct iovec respIO[3];
186 respIO[0].iov_base = (caddr_t)&resp;
187 respIO[0].iov_len =
sizeof(resp);
188 kXR_int32 xbuf =
static_cast<kXR_int32
>(htonl(info));
191 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
192 respIO[1].iov_base = (caddr_t)(&xbuf);
193 respIO[1].iov_len =
sizeof(xbuf);
196 respIO[2].iov_base = (caddr_t)data;
197 respIO[2].iov_len = dlen = strlen(data);
199 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+
sizeof(xbuf))));
202 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
206 XPDFORM(tmsg,
"sending %d data bytes; info=%d; status=%d", dlen, info, rcode);
208 XPDFORM(tmsg,
"sending info=%d; status=%d", info, rcode);
218 void *data,
int dlen )
220 XPDLOC(RSP,
"Response::Send:6")
225 XrdOucString tmsg, emsg;
226 ServerResponseHeader resp;
228 struct iovec respIO[3];
229 respIO[0].iov_base = (caddr_t)&resp;
230 respIO[0].iov_len =
sizeof(resp);
231 kXR_int32 xbuf =
static_cast<kXR_int32
>(htonl(acode));
233 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
234 respIO[1].iov_base = (caddr_t)(&xbuf);
235 respIO[1].iov_len =
sizeof(xbuf);
238 respIO[2].iov_base = (caddr_t)data;
239 respIO[2].iov_len = dlen;
241 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+
sizeof(xbuf))));
243 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
247 XPDFORM(tmsg,
"sending %d data bytes; status=%d; action=%d",
250 XPDFORM(tmsg,
"sending status=%d; action=%d", rcode, acode);
261 kXR_int32 cid,
void *data,
int dlen )
263 XPDLOC(RSP,
"Response::Send:7")
268 XrdOucString tmsg, emsg;
269 ServerResponseHeader resp;
271 struct iovec respIO[4];
272 respIO[0].iov_base = (caddr_t)&resp;
273 respIO[0].iov_len =
sizeof(resp);
275 kXR_int32 xbuf =
static_cast<kXR_int32
>(htonl(acode));
276 kXR_int32 xcid =
static_cast<kXR_int32
>(htonl(cid));
277 int hlen =
sizeof(xbuf) +
sizeof(xcid);
279 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
280 respIO[1].iov_base = (caddr_t)(&xbuf);
281 respIO[1].iov_len =
sizeof(xbuf);
282 respIO[2].iov_base = (caddr_t)(&xcid);
283 respIO[2].iov_len =
sizeof(xcid);
286 respIO[3].iov_base = (caddr_t)data;
287 respIO[3].iov_len = dlen;
289 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+hlen)));
291 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
295 XPDFORM(tmsg,
"sending %d data bytes; status=%d; action=%d; cid=%d",
296 dlen, rcode, acode, cid);
298 XPDFORM(tmsg,
"sending status=%d; action=%d; cid=%d", rcode, acode, cid);
311 XPDLOC(RSP,
"Response::Send:8")
316 XrdOucString tmsg, emsg;
317 ServerResponseHeader resp;
319 struct iovec respIO[3];
320 respIO[0].iov_base = (caddr_t)&resp;
321 respIO[0].iov_len =
sizeof(resp);
322 kXR_int32 xbuf =
static_cast<kXR_int32
>(htonl(acode));
323 kXR_int32 xinf =
static_cast<kXR_int32
>(htonl(info));
324 int hlen =
sizeof(xbuf) +
sizeof(xinf);
325 resp.status =
static_cast<kXR_unt16
>(htons(rcode));
326 respIO[1].iov_base = (caddr_t)(&xbuf);
327 respIO[1].iov_len =
sizeof(xbuf);
328 respIO[2].iov_base = (caddr_t)(&xinf);
329 respIO[2].iov_len =
sizeof(xinf);
330 resp.dlen =
static_cast<kXR_int32
>(htonl((hlen)));
332 rc =
LinkSend(respIO, 3,
sizeof(resp), emsg);
335 XPDFORM(tmsg,
"sending info=%d; status=%d; action=%d", info, rcode, acode);
344 void *data,
int dlen )
346 XPDLOC(RSP,
"Response::SendI:1")
351 XrdOucString tmsg, emsg;
352 ServerResponseHeader resp;
354 struct iovec respIO[5];
355 respIO[0].iov_base = (caddr_t)&resp;
356 respIO[0].iov_len =
sizeof(resp);
357 kXR_int32 i1 =
static_cast<kXR_int32
>(htonl(int1));
358 kXR_int16 i2 =
static_cast<kXR_int16
>(htons(int2));
359 kXR_int16 i3 =
static_cast<kXR_int16
>(htons(int3));
360 int ilen =
sizeof(i1) +
sizeof(i2) +
sizeof(i3);
362 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
363 respIO[1].iov_base = (caddr_t)(&i1);
364 respIO[1].iov_len =
sizeof(i1);
365 respIO[2].iov_base = (caddr_t)(&i2);
366 respIO[2].iov_len =
sizeof(i2);
367 respIO[3].iov_base = (caddr_t)(&i3);
368 respIO[3].iov_len =
sizeof(i3);
371 respIO[4].iov_base = (caddr_t)data;
372 respIO[4].iov_len = dlen;
374 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+ilen)));
376 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
380 XPDFORM(tmsg,
"sending %d data bytes; int1=%d; int2=%d; int3=%d",
381 dlen, int1, int2, int3);
383 XPDFORM(tmsg,
"sending int1=%d; int2=%d; int3=%d", int1, int2, int3);
395 XPDLOC(RSP,
"Response::SendI:2")
400 XrdOucString tmsg, emsg;
401 ServerResponseHeader resp;
403 struct iovec respIO[4];
404 respIO[0].iov_base = (caddr_t)&resp;
405 respIO[0].iov_len =
sizeof(resp);
406 kXR_int32 i1 =
static_cast<kXR_int32
>(htonl(int1));
407 kXR_int32 i2 =
static_cast<kXR_int32
>(htonl(int2));
408 int ilen =
sizeof(i1) +
sizeof(i2);
410 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
411 respIO[1].iov_base = (caddr_t)(&i1);
412 respIO[1].iov_len =
sizeof(i1);
413 respIO[2].iov_base = (caddr_t)(&i2);
414 respIO[2].iov_len =
sizeof(i2);
417 respIO[3].iov_base = (caddr_t)data;
418 respIO[3].iov_len = dlen;
420 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+ilen)));
422 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
426 XPDFORM(tmsg,
"sending %d data bytes; int1=%d; int2=%d",
429 XPDFORM(tmsg,
"sending int1=%d; int2=%d", int1, int2);
441 XPDLOC(RSP,
"Response::SendI:3")
446 XrdOucString tmsg, emsg;
447 ServerResponseHeader resp;
449 struct iovec respIO[3];
450 respIO[0].iov_base = (caddr_t)&resp;
451 respIO[0].iov_len =
sizeof(resp);
453 kXR_int32 i1 =
static_cast<kXR_int32
>(htonl(int1));
454 int ilen =
sizeof(i1);
456 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
457 respIO[1].iov_base = (caddr_t)(&i1);
458 respIO[1].iov_len =
sizeof(i1);
461 respIO[2].iov_base = (caddr_t)data;
462 respIO[2].iov_len = dlen;
464 resp.dlen =
static_cast<kXR_int32
>(htonl((dlen+ilen)));
466 rc =
LinkSend(respIO, nn,
sizeof(resp) + dlen, emsg);
470 XPDFORM(tmsg,
"sending %d data bytes; int1=%d", dlen, int1);
472 XPDFORM(tmsg,
"sending int1=%d", int1);
484 XPDLOC(RSP,
"Response::Send:9")
489 XrdOucString tmsg, emsg;
490 ServerResponseHeader resp;
492 struct iovec respIO[2];
493 respIO[0].iov_base = (caddr_t)&resp;
494 respIO[0].iov_len =
sizeof(resp);
495 resp.status =
static_cast<kXR_unt16
>(htons(kXR_ok));
496 respIO[1].iov_base = (caddr_t)data;
497 respIO[1].iov_len = dlen;
498 resp.dlen =
static_cast<kXR_int32
>(htonl(dlen));
500 rc =
LinkSend(respIO, 2,
sizeof(resp) + dlen, emsg);
512 XPDLOC(RSP,
"Response::Send:11")
517 XrdOucString tmsg, emsg;
518 ServerResponseHeader resp;
520 struct iovec respIO[3];
521 respIO[0].iov_base = (caddr_t)&resp;
522 respIO[0].iov_len =
sizeof(resp);
524 kXR_int32 erc =
static_cast<kXR_int32
>(htonl(ecode));
525 resp.status =
static_cast<kXR_unt16
>(htons(kXR_error));
526 respIO[1].iov_base = (
char *)&erc;
527 respIO[1].iov_len =
sizeof(erc);
528 respIO[2].iov_base = (caddr_t)msg;
529 respIO[2].iov_len = strlen(msg)+1;
530 dlen =
sizeof(erc) + respIO[2].iov_len;
531 resp.dlen =
static_cast<kXR_int32
>(htonl(dlen));
533 rc =
LinkSend(respIO, 3,
sizeof(resp) + dlen, emsg);
545 XPDLOC(RSP,
"Response::Send:12")
550 XrdOucString tmsg, emsg;
551 ServerResponseHeader resp;
553 struct iovec respIO[3];
554 respIO[0].iov_base = (caddr_t)&resp;
555 respIO[0].iov_len =
sizeof(resp);
557 kXR_int32 erc =
static_cast<kXR_int32
>(htonl(ecode));
558 resp.status =
static_cast<kXR_unt16
>(htons(kXR_error));
559 respIO[1].iov_base = (
char *)&erc;
560 respIO[1].iov_len =
sizeof(erc);
561 respIO[2].iov_base = (caddr_t)msg;
562 respIO[2].iov_len = strlen(msg)+1;
563 dlen =
sizeof(erc) + respIO[2].iov_len;
564 resp.dlen =
static_cast<kXR_int32
>(htonl(dlen));
566 rc =
LinkSend(respIO, 3,
sizeof(resp) + dlen, emsg);
581 XPDLOC(RSP,
"Response::LinkSend:1")
583 XrdSysMutexHelper mxh(
fMutex);
589 if ((rc =
fLink->Send(buff, len)) < 0) {
590 XPDFORM(emsg,
"problems sending %d bytes", len);
596 return ((rc < 0) ?
fLink->setEtext(
"send failure") : 0);
613 int iocnt,
int, XrdOucString &emsg)
615 XPDLOC(RSP,
"Response::LinkSend:2")
618 XrdSysMutexHelper mxh(
fMutex);
622 if ((rc =
fLink->Send(iov, iocnt, 0)) < 0) {
624 for (
int i = 0; i < iocnt; i++) bytes += iov[i].iov_len;
625 XPDFORM(emsg,
"problems sending %d bytes (writev)", bytes);
631 return ((rc < 0) ?
fLink->setEtext(
"send (writev) failure") : 0);
646 XrdSysMutexHelper mh(
fMutex);
648 fResp.streamid[0] = stream[0];
649 fResp.streamid[1] = stream[1];
659 unsigned char stream[2];
661 { XrdSysMutexHelper mh(
fMutex);
663 memcpy((
void *)&stream[0], (
const void *)&sid,
sizeof(sid));
665 fResp.streamid[0] = stream[0];
666 fResp.streamid[1] = stream[1];
676 XrdSysMutexHelper mh(
fMutex);
677 memcpy((
void *)&sid, (
void *)&
fResp.streamid[0],
sizeof(sid));
686 XrdSysMutexHelper mh(
fMutex);
687 resp->streamid[0] =
fResp.streamid[0];
688 resp->streamid[1] =
fResp.streamid[1];
697 { XrdSysMutexHelper mh(
fMutex);
699 memcpy((
void *)&
fSID, (
void *)&
fResp.streamid[0],
sizeof(
fSID));
708 XPDLOC(RSP,
"Response::SetTraceID")
710 { XrdSysMutexHelper mh(
fMutex);
715 }
else if (
fTag.length() > 0) {
730 static char hv[] =
"0123456789abcdef";
734 for (i = 0; i < (
int)
sizeof(
fResp.streamid); i++) {
735 *outbuff++ = hv[(
fResp.streamid[i] >> 4) & 0x0f];
736 *outbuff++ = hv[
fResp.streamid[i] & 0x0f];
#define TRACE(Flag, Args)
void Set(XrdLink *l)
Set the link to be used by this response.
void GetSID(unsigned short &sid)
Get stream ID (to be able to restore it later.
int Send(void)
Auxilliary Send method.
int LinkSend(const char *buff, int len, XrdOucString &e)
Method actually sending the buffer(s) over the link.
int SendI(kXR_int32 int1, void *data=0, int dlen=0)
Auxilliary Send method.
ServerResponseHeader fResp
void SetTrsid()
Auxilliary Set method.
void SetTraceID()
Auxilliary set method.