Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
XrdProofdResponse.cxx
Go to the documentation of this file.
1// @(#)root/proofd:$Id$
2// Author: Gerardo Ganis 12/12/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// XrdProofdResponse //
15// //
16// Authors: G. Ganis, CERN, 2005 //
17// //
18// Utility class to handle replies to clients. //
19// //
20//////////////////////////////////////////////////////////////////////////
21
22#include <sys/types.h>
23#ifndef ROOT_XrdFour
24# include <netinet/in.h>
25#endif
26#include <inttypes.h>
27#include <string.h>
28
29#include "XrdProofdAux.h"
30#include "XrdProofdProtocol.h"
31#include "XrdProofdResponse.h"
32
33// Tracing utils
34#include "XrdProofdTrace.h"
35
36// Notification macro
37#define XPRNOTIFY(m,e) \
38 if (rc != 0) { \
39 TRACET(TraceID(), XERR, m << ": " << e); \
40 } else { \
41 if (TRACING(RSP)) { \
42 if (e.length() > 0) { \
43 TRACET(TraceID(), RSP, m << " (" << e <<")"); \
44 } else { \
45 TRACET(TraceID(), RSP, m); \
46 } \
47 } \
48 }
49// Tracing condition
50#define XPRTRACING(a) ((a != 0) || (TRACING(RSP)))
51// Check link macro
52#define CHECKLINK \
53 { XrdSysMutexHelper mh(fMutex); \
54 if (!fLink) { \
55 TRACE(XERR, "link is undefined! "); \
56 return 0; \
57 } else if (fLink->FDnum() < 0) { \
58 TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")"); \
59 return 0; \
60 } \
61 }
62#define CHECKLINKNOMTX \
63 if (!fLink) { \
64 TRACE(XERR, "link is undefined! "); \
65 return 0; \
66 } else if (fLink->FDnum() < 0) { \
67 TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")"); \
68 return 0; \
69 }
70
71////////////////////////////////////////////////////////////////////////////////
72/// Auxilliary Send method
73
75{
76 XPDLOC(RSP, "Response::Send:1")
77
79
80 int rc = 0;
81 XrdOucString tmsg, emsg;
82 ServerResponseHeader resp;
83 Set(&resp);
84 resp.status = static_cast<kXR_unt16>(htons(kXR_ok));
85 resp.dlen = 0;
86 // Send over
87 rc = LinkSend((char *)&resp, sizeof(resp), emsg);
88
89 XPRNOTIFY("sending OK", emsg);
90 return rc;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Auxilliary Send method
95
96int XrdProofdResponse::Send(XResponseType rcode)
97{
98 XPDLOC(RSP, "Response::Send:2")
99
100 CHECKLINK;
101
102 int rc = 0;
103 XrdOucString tmsg, emsg;
104 ServerResponseHeader resp;
105 Set(&resp);
106 resp.status = static_cast<kXR_unt16>(htons(rcode));
107 resp.dlen = 0;
108 // Send over
109 rc = LinkSend((char *)&resp, sizeof(resp), emsg);
110 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending OK: status = %d", rcode);
111
112 XPRNOTIFY(tmsg, emsg);
113 return rc;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Auxilliary Send method
118
119int XrdProofdResponse::Send(const char *msg)
120{
121 XPDLOC(RSP, "Response::Send:3")
122
123 CHECKLINK;
124
125 int rc = 0;
126 XrdOucString tmsg, emsg;
127 ServerResponseHeader resp;
128 Set(&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));
136 // Send over
137 rc = LinkSend(respIO, 2, sizeof(resp) + respIO[1].iov_len, emsg);
138 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending OK: %s", msg);
139
140 XPRNOTIFY(tmsg, emsg);
141 return rc;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Auxilliary Send method
146
147int XrdProofdResponse::Send(XResponseType rcode, void *data, int dlen)
148{
149 XPDLOC(RSP, "Response::Send:4")
150
151 CHECKLINK;
152
153 int rc = 0;
154 XrdOucString tmsg, emsg;
155 ServerResponseHeader resp;
156 Set(&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));
164 // Send over
165 rc = LinkSend(respIO, 2, sizeof(resp) + dlen, emsg);
166
167 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending %d data bytes; status=%d", dlen, rcode);
168 XPRNOTIFY(tmsg, emsg);
169 return rc;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Auxilliary Send method
174
175int XrdProofdResponse::Send(XResponseType rcode, int info, char *data)
176{
177 XPDLOC(RSP, "Response::Send:5")
178
179 CHECKLINK;
180
181 int rc = 0;
182 XrdOucString tmsg, emsg;
183 ServerResponseHeader resp;
184 Set(&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));
189 int dlen = 0;
190 int nn = 2;
191 resp.status = static_cast<kXR_unt16>(htons(rcode));
192 respIO[1].iov_base = (caddr_t)(&xbuf);
193 respIO[1].iov_len = sizeof(xbuf);
194 if (data) {
195 nn = 3;
196 respIO[2].iov_base = (caddr_t)data;
197 respIO[2].iov_len = dlen = strlen(data);
198 }
199 resp.dlen = static_cast<kXR_int32>(htonl((dlen+sizeof(xbuf))));
200
201 // Send over
202 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
203
204 if (XPRTRACING(rc)) {
205 if (data)
206 XPDFORM(tmsg, "sending %d data bytes; info=%d; status=%d", dlen, info, rcode);
207 else
208 XPDFORM(tmsg, "sending info=%d; status=%d", info, rcode);
209 }
210 XPRNOTIFY(tmsg, emsg);
211 return rc;
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Auxilliary Send method
216
217int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
218 void *data, int dlen )
219{
220 XPDLOC(RSP, "Response::Send:6")
221
222 CHECKLINK;
223
224 int rc = 0;
225 XrdOucString tmsg, emsg;
226 ServerResponseHeader resp;
227 Set(&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));
232 int nn = 2;
233 resp.status = static_cast<kXR_unt16>(htons(rcode));
234 respIO[1].iov_base = (caddr_t)(&xbuf);
235 respIO[1].iov_len = sizeof(xbuf);
236 if (data) {
237 nn = 3;
238 respIO[2].iov_base = (caddr_t)data;
239 respIO[2].iov_len = dlen;
240 }
241 resp.dlen = static_cast<kXR_int32>(htonl((dlen+sizeof(xbuf))));
242 // Send over
243 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
244
245 if (XPRTRACING(rc)) {
246 if (data) {
247 XPDFORM(tmsg, "sending %d data bytes; status=%d; action=%d",
248 dlen, rcode, acode);
249 } else {
250 XPDFORM(tmsg, "sending status=%d; action=%d", rcode, acode);
251 }
252 }
253 XPRNOTIFY(tmsg, emsg);
254 return rc;
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Auxilliary Send method
259
260int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
261 kXR_int32 cid, void *data, int dlen )
262{
263 XPDLOC(RSP, "Response::Send:7")
264
265 CHECKLINK;
266
267 int rc = 0;
268 XrdOucString tmsg, emsg;
269 ServerResponseHeader resp;
270 Set(&resp);
271 struct iovec respIO[4];
272 respIO[0].iov_base = (caddr_t)&resp;
273 respIO[0].iov_len = sizeof(resp);
274
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);
278 int nn = 3;
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);
284 if (data) {
285 nn = 4;
286 respIO[3].iov_base = (caddr_t)data;
287 respIO[3].iov_len = dlen;
288 }
289 resp.dlen = static_cast<kXR_int32>(htonl((dlen+hlen)));
290 // Send over
291 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
292
293 if (XPRTRACING(rc)) {
294 if (data) {
295 XPDFORM(tmsg, "sending %d data bytes; status=%d; action=%d; cid=%d",
296 dlen, rcode, acode, cid);
297 } else {
298 XPDFORM(tmsg, "sending status=%d; action=%d; cid=%d", rcode, acode, cid);
299 }
300 }
301 XPRNOTIFY(tmsg, emsg);
302 return rc;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Auxilliary Send method
307
308int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
309 int info )
310{
311 XPDLOC(RSP, "Response::Send:8")
312
313 CHECKLINK;
314
315 int rc = 0;
316 XrdOucString tmsg, emsg;
317 ServerResponseHeader resp;
318 Set(&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)));
331 // Send over
332 rc = LinkSend(respIO, 3, sizeof(resp), emsg);
333
334 if (XPRTRACING(rc))
335 XPDFORM(tmsg, "sending info=%d; status=%d; action=%d", info, rcode, acode);
336 XPRNOTIFY(tmsg, emsg);
337 return rc;
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Auxilliary Send method
342
343int XrdProofdResponse::SendI(kXR_int32 int1, kXR_int16 int2, kXR_int16 int3,
344 void *data, int dlen )
345{
346 XPDLOC(RSP, "Response::SendI:1")
347
348 CHECKLINK;
349
350 int rc = 0;
351 XrdOucString tmsg, emsg;
352 ServerResponseHeader resp;
353 Set(&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);
361 int nn = 4;
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);
369 if (data) {
370 nn = 5;
371 respIO[4].iov_base = (caddr_t)data;
372 respIO[4].iov_len = dlen;
373 }
374 resp.dlen = static_cast<kXR_int32>(htonl((dlen+ilen)));
375 // Send over
376 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
377
378 if (XPRTRACING(rc)) {
379 if (data) {
380 XPDFORM(tmsg, "sending %d data bytes; int1=%d; int2=%d; int3=%d",
381 dlen, int1, int2, int3);
382 } else {
383 XPDFORM(tmsg, "sending int1=%d; int2=%d; int3=%d", int1, int2, int3);
384 }
385 }
386 XPRNOTIFY(tmsg, emsg);
387 return rc;
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Auxilliary Send method
392
393int XrdProofdResponse::SendI(kXR_int32 int1, kXR_int32 int2, void *data, int dlen )
394{
395 XPDLOC(RSP, "Response::SendI:2")
396
397 CHECKLINK;
398
399 int rc = 0;
400 XrdOucString tmsg, emsg;
401 ServerResponseHeader resp;
402 Set(&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);
409 int nn = 3;
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);
415 if (data) {
416 nn = 4;
417 respIO[3].iov_base = (caddr_t)data;
418 respIO[3].iov_len = dlen;
419 }
420 resp.dlen = static_cast<kXR_int32>(htonl((dlen+ilen)));
421 // Send over
422 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
423
424 if (XPRTRACING(rc)) {
425 if (data) {
426 XPDFORM(tmsg, "sending %d data bytes; int1=%d; int2=%d",
427 dlen, int1, int2);
428 } else {
429 XPDFORM(tmsg, "sending int1=%d; int2=%d", int1, int2);
430 }
431 }
432 XPRNOTIFY(tmsg, emsg);
433 return rc;
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Auxilliary Send method
438
439int XrdProofdResponse::SendI(kXR_int32 int1, void *data, int dlen )
440{
441 XPDLOC(RSP, "Response::SendI:3")
442
443 CHECKLINK;
444
445 int rc = 0;
446 XrdOucString tmsg, emsg;
447 ServerResponseHeader resp;
448 Set(&resp);
449 struct iovec respIO[3];
450 respIO[0].iov_base = (caddr_t)&resp;
451 respIO[0].iov_len = sizeof(resp);
452
453 kXR_int32 i1 = static_cast<kXR_int32>(htonl(int1));
454 int ilen = sizeof(i1);
455 int nn = 2;
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);
459 if (data) {
460 nn = 3;
461 respIO[2].iov_base = (caddr_t)data;
462 respIO[2].iov_len = dlen;
463 }
464 resp.dlen = static_cast<kXR_int32>(htonl((dlen+ilen)));
465 // Send over
466 rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
467
468 if (XPRTRACING(rc)) {
469 if (data) {
470 XPDFORM(tmsg, "sending %d data bytes; int1=%d", dlen, int1);
471 } else {
472 XPDFORM(tmsg, "sending int1=%d", int1);
473 }
474 }
475 XPRNOTIFY(tmsg, emsg);
476 return rc;
477}
478
479////////////////////////////////////////////////////////////////////////////////
480/// Auxilliary Send method
481
482int XrdProofdResponse::Send(void *data, int dlen)
483{
484 XPDLOC(RSP, "Response::Send:9")
485
486 CHECKLINK;
487
488 int rc = 0;
489 XrdOucString tmsg, emsg;
490 ServerResponseHeader resp;
491 Set(&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));
499 // Send over
500 rc = LinkSend(respIO, 2, sizeof(resp) + dlen, emsg);
501
502 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending %d data bytes; status=0", dlen);
503 XPRNOTIFY(tmsg, emsg);
504 return rc;
505}
506
507////////////////////////////////////////////////////////////////////////////////
508/// Auxilliary Send method
509
510int XrdProofdResponse::Send(XErrorCode ecode, const char *msg)
511{
512 XPDLOC(RSP, "Response::Send:11")
513
514 CHECKLINK;
515
516 int rc = 0;
517 XrdOucString tmsg, emsg;
518 ServerResponseHeader resp;
519 Set(&resp);
520 struct iovec respIO[3];
521 respIO[0].iov_base = (caddr_t)&resp;
522 respIO[0].iov_len = sizeof(resp);
523 int dlen;
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));
532 // Send over
533 rc = LinkSend(respIO, 3, sizeof(resp) + dlen, emsg);
534
535 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending err %d: %s", ecode, msg);
536 XPRNOTIFY(tmsg, emsg);
537 return rc;
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Auxilliary Send method
542
543int XrdProofdResponse::Send(XPErrorCode ecode, const char *msg)
544{
545 XPDLOC(RSP, "Response::Send:12")
546
547 CHECKLINK;
548
549 int rc = 0;
550 XrdOucString tmsg, emsg;
551 ServerResponseHeader resp;
552 Set(&resp);
553 struct iovec respIO[3];
554 respIO[0].iov_base = (caddr_t)&resp;
555 respIO[0].iov_len = sizeof(resp);
556 int dlen;
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));
565 // Send over
566 rc = LinkSend(respIO, 3, sizeof(resp) + dlen, emsg);
567
568 if (XPRTRACING(rc)) XPDFORM(tmsg, "sending err %d: %s", ecode, msg);
569 XPRNOTIFY(tmsg, emsg);
570 return rc;
571}
572
573////////////////////////////////////////////////////////////////////////////////
574/// Method actually sending the buffer(s) over the link.
575/// The link is closed in case of error, because we cannot use it anymore
576/// and the counter part needs to reconnect.
577/// Return 0 on success, -1 on failure.
578
579int XrdProofdResponse::LinkSend(const char *buff, int len, XrdOucString &emsg)
580{
581 XPDLOC(RSP, "Response::LinkSend:1")
582
583 XrdSysMutexHelper mxh(fMutex);
585
586 int rc = 0;
587
588 // If we fail we close the link, and ask the client to reconnect
589 if ((rc = fLink->Send(buff, len)) < 0) {
590 XPDFORM(emsg, "problems sending %d bytes", len);
591#if 0
592 fLink->Close();
593 }
594
595 // Done
596 return ((rc < 0) ? fLink->setEtext("send failure") : 0);
597#else
598 fLink = 0;
599 return -1;
600 }
601 // Done
602 return 0;
603#endif
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Method actually sending the buffer(s) over the link.
608/// Functionality a la 'writev' is simulated by segmenting the sending.
609/// This allows to avoid a recovery problem with 'writev'.
610/// Return 0 on success, -1 on failure.
611
612int XrdProofdResponse::LinkSend(const struct iovec *iov,
613 int iocnt, int, XrdOucString &emsg)
614{
615 XPDLOC(RSP, "Response::LinkSend:2")
616
617 int rc = 0;
618 XrdSysMutexHelper mxh(fMutex);
620
621 // If we fail we close the link, and ask the client to reconnect
622 if ((rc = fLink->Send(iov, iocnt, 0)) < 0) {
623 int bytes = 0;
624 for (int i = 0; i < iocnt; i++) bytes += iov[i].iov_len;
625 XPDFORM(emsg, "problems sending %d bytes (writev)", bytes);
626#if 0
627 fLink->Close();
628 }
629
630 // Done
631 return ((rc < 0) ? fLink->setEtext("send (writev) failure") : 0);
632#else
633 fLink = 0;
634 return -1;
635 }
636 // Done
637 return 0;
638#endif
639}
640
641////////////////////////////////////////////////////////////////////////////////
642/// Auxilliary Set method
643
644void XrdProofdResponse::Set(unsigned char *stream)
645{
646 XrdSysMutexHelper mh(fMutex);
647
648 fResp.streamid[0] = stream[0];
649 fResp.streamid[1] = stream[1];
650
651 SetTrsid();
652}
653
654////////////////////////////////////////////////////////////////////////////////
655/// Auxilliary Set method
656
657void XrdProofdResponse::Set(unsigned short sid)
658{
659 unsigned char stream[2];
660
661 { XrdSysMutexHelper mh(fMutex);
662
663 memcpy((void *)&stream[0], (const void *)&sid, sizeof(sid));
664
665 fResp.streamid[0] = stream[0];
666 fResp.streamid[1] = stream[1];
667 }
668 SetTrsid();
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Get stream ID (to be able to restore it later
673
674void XrdProofdResponse::GetSID(unsigned short &sid)
675{
676 XrdSysMutexHelper mh(fMutex);
677 memcpy((void *)&sid, (void *)&fResp.streamid[0], sizeof(sid));
678}
679
680////////////////////////////////////////////////////////////////////////////////
681/// Fill the stream id
682
683void XrdProofdResponse::Set(ServerResponseHeader *resp)
684{
685 if (resp) {
686 XrdSysMutexHelper mh(fMutex);
687 resp->streamid[0] = fResp.streamid[0];
688 resp->streamid[1] = fResp.streamid[1];
689 }
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Set the link to be used by this response
694
696{
697 { XrdSysMutexHelper mh(fMutex);
698 fLink = l;
699 memcpy((void *)&fSID, (void *)&fResp.streamid[0], sizeof(fSID));
700 }
701}
702
703////////////////////////////////////////////////////////////////////////////////
704/// Auxilliary set method
705
707{
708 XPDLOC(RSP, "Response::SetTraceID")
709
710 { XrdSysMutexHelper mh(fMutex);
711 if (fLink && fTag.length() > 0) {
712 XPDFORM(fTraceID, "%s%s: %s: ", fTrsid, fLink->ID, fTag.c_str());
713 } else if (fLink) {
714 XPDFORM(fTraceID, "%s%s: ", fTrsid, fLink->ID);
715 } else if (fTag.length() > 0) {
716 XPDFORM(fTraceID, "%s%s: ", fTrsid, fTag.c_str());
717 } else {
718 XPDFORM(fTraceID, "%s: ", fTrsid);
719 }
720 }
721
722 TRACE(DBG,"trace set to '"<<fTraceID<<"'")
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Auxilliary Set method
727
729{
730 static char hv[] = "0123456789abcdef";
731
732 int i;
733 char *outbuff = fTrsid;
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];
737 }
738 *outbuff++ = ' ';
739 *outbuff = '\0';
740}
741
#define TRACE(Flag, Args)
Definition TGHtml.h:120
XPErrorCode
XProofActionCode
#define XPDFORM
#define XPRNOTIFY(m, e)
#define XPRTRACING(a)
#define CHECKLINKNOMTX
#define CHECKLINK
#define XPDLOC(d, x)
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.
unsigned short fSID
int SendI(kXR_int32 int1, void *data=0, int dlen=0)
Auxilliary Send method.
ServerResponseHeader fResp
void SetTrsid()
Auxilliary Set method.
XrdSysRecMutex fMutex
void SetTraceID()
Auxilliary set method.
auto * l
Definition textangle.C:4