XrdProofdResponse.cxx

Go to the documentation of this file.
00001 // @(#)root/proofd:$Id: XrdProofdResponse.cxx 30920 2009-10-29 18:17:44Z ganis $
00002 // Author: Gerardo Ganis  12/12/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // XrdProofdResponse                                                    //
00015 //                                                                      //
00016 // Authors: G. Ganis, CERN, 2005                                        //
00017 //                                                                      //
00018 // Utility class to handle replies to clients.                          //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include <sys/types.h>
00023 #include <netinet/in.h>
00024 #include <inttypes.h>
00025 #include <string.h>
00026 
00027 #include "XrdProofdAux.h"
00028 #include "XrdProofdProtocol.h"
00029 #include "XrdProofdResponse.h"
00030 
00031 // Tracing utils
00032 #include "XrdProofdTrace.h"
00033 
00034 // Notification macro
00035 #define XPRNOTIFY(m,e) \
00036    if (rc != 0) { \
00037       TRACER(this, XERR, m << ": " << e); \
00038    } else { \
00039       if (TRACING(RSP)) { \
00040          if (e.length() > 0) { \
00041             TRACER(this, RSP, m << " (" << e <<")"); \
00042          } else { \
00043             TRACER(this, RSP, m); \
00044          } \
00045       } \
00046    }
00047 // Tracing condition
00048 #define XPRTRACING(a) ((a != 0) || (TRACING(RSP)))
00049 // Check link macro
00050 #define CHECKLINK \
00051    if (!fLink) { \
00052       TRACE(XERR, "link is undefined! "); \
00053       return 0; \
00054    } else if (fLink->FDnum() < 0) { \
00055       TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")"); \
00056       return 0; \
00057    }
00058 
00059 //______________________________________________________________________________
00060 int XrdProofdResponse::Send()
00061 {
00062    // Auxilliary Send method
00063    XPDLOC(RSP, "Response::Send:1")
00064 
00065    CHECKLINK;
00066 
00067    int rc = 0;
00068    XrdOucString tmsg, emsg;
00069    ServerResponseHeader resp;
00070    Set(&resp);
00071    resp.status = static_cast<kXR_unt16>(htons(kXR_ok));
00072    resp.dlen   = 0;
00073    // Send over
00074    rc = LinkSend((char *)&resp, sizeof(resp), emsg);
00075 
00076    XPRNOTIFY("sending OK", emsg);
00077    return rc;
00078 }
00079 
00080 //______________________________________________________________________________
00081 int XrdProofdResponse::Send(XResponseType rcode)
00082 {
00083    // Auxilliary Send method
00084    XPDLOC(RSP, "Response::Send:2")
00085 
00086    CHECKLINK;
00087 
00088    int rc = 0;
00089    XrdOucString tmsg, emsg;
00090    ServerResponseHeader resp;
00091    Set(&resp);
00092    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00093    resp.dlen          = 0;
00094    // Send over
00095    rc = LinkSend((char *)&resp, sizeof(resp), emsg);
00096    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending OK: status = %d", rcode);
00097 
00098    XPRNOTIFY(tmsg, emsg);
00099    return rc;
00100 }
00101 
00102 //______________________________________________________________________________
00103 int XrdProofdResponse::Send(const char *msg)
00104 {
00105    // Auxilliary Send method
00106    XPDLOC(RSP, "Response::Send:3")
00107 
00108    CHECKLINK;
00109 
00110    int rc = 0;
00111    XrdOucString tmsg, emsg;
00112    ServerResponseHeader resp;
00113    Set(&resp);
00114    struct iovec         respIO[2];
00115    respIO[0].iov_base = (caddr_t)&resp;
00116    respIO[0].iov_len  = sizeof(resp);
00117    resp.status        = static_cast<kXR_unt16>(htons(kXR_ok));
00118    respIO[1].iov_base = (caddr_t)msg;
00119    respIO[1].iov_len  = strlen(msg)+1;
00120    resp.dlen          = static_cast<kXR_int32>(htonl(respIO[1].iov_len));
00121    // Send over
00122    rc = LinkSend(respIO, 2, sizeof(resp) + respIO[1].iov_len, emsg);
00123    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending OK: %s", msg);
00124 
00125    XPRNOTIFY(tmsg, emsg);
00126    return rc;
00127 }
00128 
00129 //______________________________________________________________________________
00130 int XrdProofdResponse::Send(XResponseType rcode, void *data, int dlen)
00131 {
00132    // Auxilliary Send method
00133    XPDLOC(RSP, "Response::Send:4")
00134 
00135    CHECKLINK;
00136 
00137    int rc = 0;
00138    XrdOucString tmsg, emsg;
00139    ServerResponseHeader resp;
00140    Set(&resp);
00141    struct iovec         respIO[2];
00142    respIO[0].iov_base = (caddr_t)&resp;
00143    respIO[0].iov_len  = sizeof(resp);
00144    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00145    respIO[1].iov_base = (caddr_t)data;
00146    respIO[1].iov_len  = dlen;
00147    resp.dlen          = static_cast<kXR_int32>(htonl(dlen));
00148    // Send over
00149    rc = LinkSend(respIO, 2, sizeof(resp) + dlen, emsg);
00150 
00151    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending %d data bytes; status=%d", dlen, rcode);
00152    XPRNOTIFY(tmsg, emsg);
00153    return rc;
00154 }
00155 
00156 //______________________________________________________________________________
00157 int XrdProofdResponse::Send(XResponseType rcode, int info, char *data)
00158 {
00159    // Auxilliary Send method
00160    XPDLOC(RSP, "Response::Send:5")
00161 
00162    CHECKLINK;
00163 
00164    int rc = 0;
00165    XrdOucString tmsg, emsg;
00166    ServerResponseHeader resp;
00167    Set(&resp);
00168    struct iovec         respIO[3];
00169    respIO[0].iov_base = (caddr_t)&resp;
00170    respIO[0].iov_len  = sizeof(resp);
00171    kXR_int32 xbuf = static_cast<kXR_int32>(htonl(info));
00172    int dlen = 0;
00173    int nn = 2;
00174    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00175    respIO[1].iov_base = (caddr_t)(&xbuf);
00176    respIO[1].iov_len  = sizeof(xbuf);
00177    if (data) {
00178       nn = 3;
00179       respIO[2].iov_base = (caddr_t)data;
00180       respIO[2].iov_len  = dlen = strlen(data);
00181    }
00182    resp.dlen          = static_cast<kXR_int32>(htonl((dlen+sizeof(xbuf))));
00183 
00184    // Send over
00185    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00186 
00187    if (XPRTRACING(rc)) {
00188       if (data)
00189          XPDFORM(tmsg, "sending %d data bytes; info=%d; status=%d", dlen, info, rcode);
00190       else
00191          XPDFORM(tmsg, "sending info=%d; status=%d", info, rcode);
00192    }
00193    XPRNOTIFY(tmsg, emsg);
00194    return rc;
00195 }
00196 
00197 //______________________________________________________________________________
00198 int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
00199                             void *data, int dlen )
00200 {
00201    // Auxilliary Send method
00202    XPDLOC(RSP, "Response::Send:6")
00203 
00204    CHECKLINK;
00205 
00206    int rc = 0;
00207    XrdOucString tmsg, emsg;
00208    ServerResponseHeader resp;
00209    Set(&resp);
00210    struct iovec         respIO[3];
00211    respIO[0].iov_base = (caddr_t)&resp;
00212    respIO[0].iov_len  = sizeof(resp);
00213    kXR_int32 xbuf = static_cast<kXR_int32>(htonl(acode));
00214    int nn = 2;
00215    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00216    respIO[1].iov_base = (caddr_t)(&xbuf);
00217    respIO[1].iov_len  = sizeof(xbuf);
00218    if (data) {
00219       nn = 3;
00220       respIO[2].iov_base = (caddr_t)data;
00221       respIO[2].iov_len  = dlen;
00222    }
00223    resp.dlen = static_cast<kXR_int32>(htonl((dlen+sizeof(xbuf))));
00224    // Send over
00225    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00226 
00227    if (XPRTRACING(rc)) {
00228       if (data) {
00229          XPDFORM(tmsg, "sending %d data bytes; status=%d; action=%d",
00230                        dlen, rcode, acode);
00231       } else {
00232          XPDFORM(tmsg, "sending status=%d; action=%d", rcode, acode);
00233       }
00234    }
00235    XPRNOTIFY(tmsg, emsg);
00236    return rc;
00237 }
00238 
00239 //______________________________________________________________________________
00240 int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
00241                             kXR_int32 cid, void *data, int dlen )
00242 {
00243    // Auxilliary Send method
00244    XPDLOC(RSP, "Response::Send:7")
00245 
00246    CHECKLINK;
00247 
00248    int rc = 0;
00249    XrdOucString tmsg, emsg;
00250    ServerResponseHeader resp;
00251    Set(&resp);
00252    struct iovec         respIO[4];
00253    respIO[0].iov_base = (caddr_t)&resp;
00254    respIO[0].iov_len  = sizeof(resp);
00255 
00256    kXR_int32 xbuf = static_cast<kXR_int32>(htonl(acode));
00257    kXR_int32 xcid = static_cast<kXR_int32>(htonl(cid));
00258    int hlen = sizeof(xbuf) + sizeof(xcid);
00259    int nn = 3;
00260    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00261    respIO[1].iov_base = (caddr_t)(&xbuf);
00262    respIO[1].iov_len  = sizeof(xbuf);
00263    respIO[2].iov_base = (caddr_t)(&xcid);
00264    respIO[2].iov_len  = sizeof(xcid);
00265    if (data) {
00266       nn = 4;
00267       respIO[3].iov_base = (caddr_t)data;
00268       respIO[3].iov_len  = dlen;
00269    }
00270    resp.dlen = static_cast<kXR_int32>(htonl((dlen+hlen)));
00271    // Send over
00272    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00273 
00274    if (XPRTRACING(rc)) {
00275       if (data) {
00276          XPDFORM(tmsg, "sending %d data bytes; status=%d; action=%d; cid=%d",
00277                        dlen, rcode, acode, cid);
00278       } else {
00279          XPDFORM(tmsg, "sending status=%d; action=%d; cid=%d", rcode, acode, cid);
00280       }
00281    }
00282    XPRNOTIFY(tmsg, emsg);
00283    return rc;
00284 }
00285 
00286 //______________________________________________________________________________
00287 int XrdProofdResponse::Send(XResponseType rcode, XProofActionCode acode,
00288                             int info )
00289 {
00290    // Auxilliary Send method
00291    XPDLOC(RSP, "Response::Send:8")
00292 
00293    CHECKLINK;
00294 
00295    int rc = 0;
00296    XrdOucString tmsg, emsg;
00297    ServerResponseHeader resp;
00298    Set(&resp);
00299    struct iovec         respIO[3];
00300    respIO[0].iov_base = (caddr_t)&resp;
00301    respIO[0].iov_len  = sizeof(resp);
00302    kXR_int32 xbuf = static_cast<kXR_int32>(htonl(acode));
00303    kXR_int32 xinf = static_cast<kXR_int32>(htonl(info));
00304    int hlen = sizeof(xbuf) + sizeof(xinf);
00305    resp.status        = static_cast<kXR_unt16>(htons(rcode));
00306    respIO[1].iov_base = (caddr_t)(&xbuf);
00307    respIO[1].iov_len  = sizeof(xbuf);
00308    respIO[2].iov_base = (caddr_t)(&xinf);
00309    respIO[2].iov_len  = sizeof(xinf);
00310    resp.dlen = static_cast<kXR_int32>(htonl((hlen)));
00311    // Send over
00312    rc = LinkSend(respIO, 3, sizeof(resp), emsg);
00313 
00314    if (XPRTRACING(rc))
00315       XPDFORM(tmsg, "sending info=%d; status=%d; action=%d", info, rcode, acode);
00316    XPRNOTIFY(tmsg, emsg);
00317    return rc;
00318 }
00319 
00320 //______________________________________________________________________________
00321 int XrdProofdResponse::SendI(kXR_int32 int1, kXR_int16 int2, kXR_int16 int3,
00322                             void *data, int dlen )
00323 {
00324    // Auxilliary Send method
00325    XPDLOC(RSP, "Response::SendI:1")
00326 
00327    CHECKLINK;
00328 
00329    int rc = 0;
00330    XrdOucString tmsg, emsg;
00331    ServerResponseHeader resp;
00332    Set(&resp);
00333    struct iovec         respIO[5];
00334    respIO[0].iov_base = (caddr_t)&resp;
00335    respIO[0].iov_len  = sizeof(resp);
00336    kXR_int32 i1 = static_cast<kXR_int32>(htonl(int1));
00337    kXR_int16 i2 = static_cast<kXR_int16>(htons(int2));
00338    kXR_int16 i3 = static_cast<kXR_int16>(htons(int3));
00339    int ilen = sizeof(i1) + sizeof(i2) + sizeof(i3);
00340    int nn = 4;
00341    resp.status        = static_cast<kXR_unt16>(htons(kXR_ok));
00342    respIO[1].iov_base = (caddr_t)(&i1);
00343    respIO[1].iov_len  = sizeof(i1);
00344    respIO[2].iov_base = (caddr_t)(&i2);
00345    respIO[2].iov_len  = sizeof(i2);
00346    respIO[3].iov_base = (caddr_t)(&i3);
00347    respIO[3].iov_len  = sizeof(i3);
00348    if (data) {
00349       nn = 5;
00350       respIO[4].iov_base = (caddr_t)data;
00351       respIO[4].iov_len  = dlen;
00352    }
00353    resp.dlen = static_cast<kXR_int32>(htonl((dlen+ilen)));
00354    // Send over
00355    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00356 
00357    if (XPRTRACING(rc)) {
00358       if (data) {
00359          XPDFORM(tmsg, "sending %d data bytes; int1=%d; int2=%d; int3=%d",
00360                        dlen, int1, int2, int3);
00361       } else {
00362          XPDFORM(tmsg, "sending int1=%d; int2=%d; int3=%d", int1, int2, int3);
00363       }
00364    }
00365    XPRNOTIFY(tmsg, emsg);
00366    return rc;
00367 }
00368 
00369 //______________________________________________________________________________
00370 int XrdProofdResponse::SendI(kXR_int32 int1, kXR_int32 int2, void *data, int dlen )
00371 {
00372    // Auxilliary Send method
00373    XPDLOC(RSP, "Response::SendI:2")
00374 
00375    CHECKLINK;
00376 
00377    int rc = 0;
00378    XrdOucString tmsg, emsg;
00379    ServerResponseHeader resp;
00380    Set(&resp);
00381    struct iovec         respIO[4];
00382    respIO[0].iov_base = (caddr_t)&resp;
00383    respIO[0].iov_len  = sizeof(resp);
00384    kXR_int32 i1 = static_cast<kXR_int32>(htonl(int1));
00385    kXR_int32 i2 = static_cast<kXR_int32>(htonl(int2));
00386    int ilen = sizeof(i1) + sizeof(i2);
00387    int nn = 3;
00388    resp.status        = static_cast<kXR_unt16>(htons(kXR_ok));
00389    respIO[1].iov_base = (caddr_t)(&i1);
00390    respIO[1].iov_len  = sizeof(i1);
00391    respIO[2].iov_base = (caddr_t)(&i2);
00392    respIO[2].iov_len  = sizeof(i2);
00393    if (data) {
00394       nn = 4;
00395       respIO[3].iov_base = (caddr_t)data;
00396       respIO[3].iov_len  = dlen;
00397    }
00398    resp.dlen = static_cast<kXR_int32>(htonl((dlen+ilen)));
00399    // Send over
00400    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00401 
00402    if (XPRTRACING(rc)) {
00403       if (data) {
00404          XPDFORM(tmsg, "sending %d data bytes; int1=%d; int2=%d",
00405                        dlen, int1, int2);
00406       } else {
00407          XPDFORM(tmsg, "sending int1=%d; int2=%d", int1, int2);
00408       }
00409    }
00410    XPRNOTIFY(tmsg, emsg);
00411    return rc;
00412 }
00413 
00414 //______________________________________________________________________________
00415 int XrdProofdResponse::SendI(kXR_int32 int1, void *data, int dlen )
00416 {
00417    // Auxilliary Send method
00418    XPDLOC(RSP, "Response::SendI:3")
00419 
00420    CHECKLINK;
00421 
00422    int rc = 0;
00423    XrdOucString tmsg, emsg;
00424    ServerResponseHeader resp;
00425    Set(&resp);
00426    struct iovec         respIO[3];
00427    respIO[0].iov_base = (caddr_t)&resp;
00428    respIO[0].iov_len  = sizeof(resp);
00429 
00430    kXR_int32 i1 = static_cast<kXR_int32>(htonl(int1));
00431    int ilen = sizeof(i1);
00432    int nn = 2;
00433    resp.status        = static_cast<kXR_unt16>(htons(kXR_ok));
00434    respIO[1].iov_base = (caddr_t)(&i1);
00435    respIO[1].iov_len  = sizeof(i1);
00436    if (data) {
00437       nn = 3;
00438       respIO[2].iov_base = (caddr_t)data;
00439       respIO[2].iov_len  = dlen;
00440    }
00441    resp.dlen          = static_cast<kXR_int32>(htonl((dlen+ilen)));
00442    // Send over
00443    rc = LinkSend(respIO, nn, sizeof(resp) + dlen, emsg);
00444 
00445    if (XPRTRACING(rc)) {
00446       if (data) {
00447          XPDFORM(tmsg, "sending %d data bytes; int1=%d", dlen, int1);
00448       } else {
00449          XPDFORM(tmsg, "sending int1=%d", int1);
00450       }
00451    }
00452    XPRNOTIFY(tmsg, emsg);
00453    return rc;
00454 }
00455 
00456 //______________________________________________________________________________
00457 int XrdProofdResponse::Send(void *data, int dlen)
00458 {
00459    // Auxilliary Send method
00460    XPDLOC(RSP, "Response::Send:9")
00461 
00462    CHECKLINK;
00463 
00464    int rc = 0;
00465    XrdOucString tmsg, emsg;
00466    ServerResponseHeader resp;
00467    Set(&resp);
00468    struct iovec         respIO[2];
00469    respIO[0].iov_base = (caddr_t)&resp;
00470    respIO[0].iov_len  = sizeof(resp);
00471    resp.status        = static_cast<kXR_unt16>(htons(kXR_ok));
00472    respIO[1].iov_base = (caddr_t)data;
00473    respIO[1].iov_len  = dlen;
00474    resp.dlen          = static_cast<kXR_int32>(htonl(dlen));
00475    // Send over
00476    rc = LinkSend(respIO, 2, sizeof(resp) + dlen, emsg);
00477 
00478    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending %d data bytes; status=0", dlen);
00479    XPRNOTIFY(tmsg, emsg);
00480    return rc;
00481 }
00482 
00483 //______________________________________________________________________________
00484 int XrdProofdResponse::Send(XErrorCode ecode, const char *msg)
00485 {
00486    // Auxilliary Send method
00487    XPDLOC(RSP, "Response::Send:11")
00488 
00489    CHECKLINK;
00490 
00491    int rc = 0;
00492    XrdOucString tmsg, emsg;
00493    ServerResponseHeader resp;
00494    Set(&resp);
00495    struct iovec         respIO[3];
00496    respIO[0].iov_base = (caddr_t)&resp;
00497    respIO[0].iov_len  = sizeof(resp);
00498    int dlen;
00499    kXR_int32 erc = static_cast<kXR_int32>(htonl(ecode));
00500    resp.status        = static_cast<kXR_unt16>(htons(kXR_error));
00501    respIO[1].iov_base = (char *)&erc;
00502    respIO[1].iov_len  = sizeof(erc);
00503    respIO[2].iov_base = (caddr_t)msg;
00504    respIO[2].iov_len  = strlen(msg)+1;
00505    dlen   = sizeof(erc) + respIO[2].iov_len;
00506    resp.dlen          = static_cast<kXR_int32>(htonl(dlen));
00507    // Send over
00508    rc = LinkSend(respIO, 3, sizeof(resp) + dlen, emsg);
00509 
00510    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending err %d: %s", ecode, msg);
00511    XPRNOTIFY(tmsg, emsg);
00512    return rc;
00513 }
00514 
00515 //______________________________________________________________________________
00516 int XrdProofdResponse::Send(XPErrorCode ecode, const char *msg)
00517 {
00518    // Auxilliary Send method
00519    XPDLOC(RSP, "Response::Send:12")
00520 
00521    CHECKLINK;
00522 
00523    int rc = 0;
00524    XrdOucString tmsg, emsg;
00525    ServerResponseHeader resp;
00526    Set(&resp);
00527    struct iovec         respIO[3];
00528    respIO[0].iov_base = (caddr_t)&resp;
00529    respIO[0].iov_len  = sizeof(resp);
00530    int dlen;
00531    kXR_int32 erc = static_cast<kXR_int32>(htonl(ecode));
00532    resp.status        = static_cast<kXR_unt16>(htons(kXR_error));
00533    respIO[1].iov_base = (char *)&erc;
00534    respIO[1].iov_len  = sizeof(erc);
00535    respIO[2].iov_base = (caddr_t)msg;
00536    respIO[2].iov_len  = strlen(msg)+1;
00537    dlen   = sizeof(erc) + respIO[2].iov_len;
00538    resp.dlen          = static_cast<kXR_int32>(htonl(dlen));
00539    // Send over
00540    rc = LinkSend(respIO, 3, sizeof(resp) + dlen, emsg);
00541 
00542    if (XPRTRACING(rc)) XPDFORM(tmsg, "sending err %d: %s", ecode, msg);
00543    XPRNOTIFY(tmsg, emsg);
00544    return rc;
00545 }
00546 
00547 //______________________________________________________________________________
00548 int XrdProofdResponse::LinkSend(const char *buff, int len, XrdOucString &emsg)
00549 {
00550    // Method actually sending the buffer(s) over the link.
00551    // The link is closed in case of error, because we cannot use it anymore
00552    // and the counter part needs to reconnect.
00553    // Return 0 on success, -1 on failure.
00554 
00555    int rc = 0;
00556 
00557    // If we fail we close the link, and ask the client to reconnect
00558    if ((rc = fLink->Send(buff, len)) < 0) {
00559       XPDFORM(emsg, "problems sending %d bytes", len);
00560       fLink->Close();
00561    }
00562 
00563    // Done
00564    return ((rc < 0) ? fLink->setEtext("send failure") : 0);
00565 }
00566 
00567 //______________________________________________________________________________
00568 int XrdProofdResponse::LinkSend(const struct iovec *iov,
00569                                 int iocnt, int, XrdOucString &emsg)
00570 {
00571    // Method actually sending the buffer(s) over the link.
00572    // Functionality a la 'writev' is simulated by segmenting the sending.
00573    // This allows to avoid a recovery problem with 'writev'.
00574    // Return 0 on success, -1 on failure.
00575 
00576    int rc = 0;
00577 
00578    // If we fail we close the link, and ask the client to reconnect
00579    if ((rc = fLink->Send(iov, iocnt, 0)) < 0) {
00580       int bytes = 0;
00581       for (int i = 0; i < iocnt; i++) bytes += iov[i].iov_len;
00582       XPDFORM(emsg, "problems sending %d bytes (writev)", bytes);
00583       fLink->Close();
00584    }
00585 
00586    // Done
00587    return ((rc < 0) ? fLink->setEtext("send (writev) failure") : 0);
00588 }
00589 
00590 //______________________________________________________________________________
00591 void XrdProofdResponse::Set(unsigned char *stream)
00592 {
00593    // Auxilliary Set method
00594 
00595    XrdSysMutexHelper mh(fMutex);
00596 
00597    fResp.streamid[0] = stream[0];
00598    fResp.streamid[1] = stream[1];
00599 
00600    SetTrsid();
00601 }
00602 
00603 //______________________________________________________________________________
00604 void XrdProofdResponse::Set(unsigned short sid)
00605 {
00606    // Auxilliary Set method
00607 
00608    unsigned char stream[2];
00609 
00610    {  XrdSysMutexHelper mh(fMutex);
00611 
00612       memcpy((void *)&stream[0], (const void *)&sid, sizeof(sid));
00613 
00614       fResp.streamid[0] = stream[0];
00615       fResp.streamid[1] = stream[1];
00616    }
00617    SetTrsid();
00618 }
00619 
00620 //______________________________________________________________________________
00621 void XrdProofdResponse::GetSID(unsigned short &sid)
00622 {
00623    // Get stream ID (to be able to restore it later
00624 
00625    {  XrdSysMutexHelper mh(fMutex);
00626       memcpy((void *)&sid, (void *)&fResp.streamid[0], sizeof(sid));
00627    }
00628 }
00629 
00630 //______________________________________________________________________________
00631 void XrdProofdResponse::Set(ServerResponseHeader *resp)
00632 {
00633    // Fill the stream id
00634 
00635    if (resp) {
00636       XrdSysMutexHelper mh(fMutex);
00637       resp->streamid[0] = fResp.streamid[0];
00638       resp->streamid[1] = fResp.streamid[1];
00639    }
00640 }
00641 
00642 //______________________________________________________________________________
00643 void XrdProofdResponse::Set(XrdLink *l)
00644 {
00645    // Set the link to be used by this response
00646    XPDLOC(RSP, "Response::Set")
00647 
00648    {  XrdSysMutexHelper mh(fMutex);
00649       fLink = l;
00650    }
00651    GetSID(fSID);
00652    if (fLink) {
00653       if (fLink->FDnum() < 0) {
00654          TRACE(XERR, "link descriptor invalid for link "<<fLink<<"! ("<< fLink->FDnum()<<")");
00655       } else {
00656          TRACE(DBG,"using link "<<fLink<<", descriptor:"<<fLink->FDnum());
00657       }
00658    } else {
00659       TRACE(XERR,"link is undefined!");
00660    }
00661 }
00662 
00663 //______________________________________________________________________________
00664 void XrdProofdResponse::SetTraceID()
00665 {
00666    // Auxilliary set method
00667    XPDLOC(RSP, "Response::SetTraceID")
00668 
00669    {  XrdSysMutexHelper mh(fMutex);
00670       if (fLink && fTag.length() > 0) {
00671          XPDFORM(fTraceID, "%s%s: %s: ", fTrsid, fLink->ID, fTag.c_str());
00672       } else if (fLink) {
00673          XPDFORM(fTraceID, "%s%s: ", fTrsid, fLink->ID);
00674       } else if (fTag.length() > 0) {
00675          XPDFORM(fTraceID, "%s%s: ", fTrsid, fTag.c_str());
00676       } else {
00677          XPDFORM(fTraceID, "%s: ", fTrsid);
00678       }
00679    }
00680 
00681    TRACE(DBG,"trace set to '"<<fTraceID<<"'")
00682 }
00683 
00684 //______________________________________________________________________________
00685 void XrdProofdResponse::SetTrsid()
00686 {
00687    // Auxilliary Set method
00688 
00689    static char hv[] = "0123456789abcdef";
00690 
00691    int i;
00692    char *outbuff = fTrsid;
00693    for (i = 0; i < (int)sizeof(fResp.streamid); i++) {
00694       *outbuff++ = hv[(fResp.streamid[i] >> 4) & 0x0f];
00695       *outbuff++ = hv[ fResp.streamid[i]       & 0x0f];
00696    }
00697    *outbuff++ = ' ';
00698    *outbuff = '\0';
00699 }
00700 

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