XRootD
Loading...
Searching...
No Matches
XrdXrootdTransSend.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d X r o o t d T r a n s S e n d . c c */
4/* */
5/* (c) 2013 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 "Xrd/XrdLink.hh"
33
34/******************************************************************************/
35/* S e n d */
36/******************************************************************************/
37
38int XrdXrootdTransSend::Send(const struct iovec *headP, int headN,
39 const struct iovec *tailP, int tailN)
40{
41 XrdLink::sfVec *sfVec;
42 int i, k = 0, numV = headN + tailN + 1;
43
44// Allocate a new sfVec to accomodate all the items
45//
46 if (sfFD >= 0) sfVec = new XrdLink::sfVec[numV];
47 else sfVec = new XrdLink::sfVec[numV-sfFD];
48
49// Copy the headers
50//
51 if (headP) for (i = 0; i < headN; i++, k++)
52 {sfVec[k].buffer = (char *)headP[i].iov_base;
53 sfVec[k].sendsz = headP[i].iov_len;
54 sfVec[k].fdnum = -1;
55 }
56
57// Insert the sendfile request
58//
59 if (sfFD >= 0)
60 {sfVec[k].offset = sfOff;
61 sfVec[k].sendsz = sfLen;
62 sfVec[k].fdnum = sfFD;
63 k++;
64 } else {
65 for (i = 1; i < -sfFD; i++)
66 {sfVec[k ].offset = sfVP[i].offset;
67 sfVec[k ].sendsz = sfVP[i].sendsz;
68 sfVec[k++].fdnum = sfVP[i].fdnum;
69 }
70 }
71
72// Copy the trailer
73//
74 if (tailP) for (i = 0; i < tailN; i++, k++)
75 {sfVec[k].buffer = (char *)tailP[i].iov_base;
76 sfVec[k].sendsz = tailP[i].iov_len;
77 sfVec[k].fdnum = -1;
78 }
79
80// Issue sendfile request
81//
82 k = linkP->Send(sfVec, numV);
83
84// Deallocate the vector and return the result
85//
86 delete [] sfVec;
87 return (k < 0 ? -1 : 0);
88}
int Send(const struct iovec *headP, int headN, const struct iovec *tailP, int tailN)
XrdLink * linkP
-> associated session link object (i.e. connection)
int fdnum
File descriptor for data.
int sendsz
Length of data at offset.