• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_LibBulkIO.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 
00025 #ifndef _LIB_BULK_IO_H
00026 #define _LIB_BULK_IO_H
00027 
00028 #if defined(solaris)
00029 #include <stdio.h>
00030 #include <errno.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <fcntl.h>
00034 #include <netdb.h>
00035 #include <sys/types.h>
00036 #include <sys/socket.h>
00037 #include <netinet/in.h>
00038 #include <sys/time.h>
00039 #include <unistd.h>
00040 #include <sys/mman.h>
00041 
00042 #include <netinet/in_systm.h>
00043 
00044 #include "P_InkBulkIO.h"
00045 
00046 struct InkBulkIOState
00047 {
00048   int biofd;
00049   void *sharedBuffer;
00050   int sharedBufferSize;
00051   InkBulkIOFreeBlockInfo_t freeList;
00052   struct InkBulkIOBlock *blockInfo;
00053   int numBlocks;
00054 };
00055 
00056 struct InkBulkIOSplit
00057 {
00058   char *header;
00059   int nbytes;
00060   struct InkBulkIOAddrInfo dest;
00061 };
00062 
00063 struct InkBulkIOAggregator
00064 {
00065   InkBulkIOAggregator()
00066   {
00067     metaReqCount = 0;
00068     metablockInfo.ptr = NULL;
00069     metablockInfo.id = 0xffffffff;
00070     metablockReqPtr = NULL;
00071 
00072     lastReqFragCount = 0;
00073     lastReq = NULL;
00074     reqblockInfo.ptr = NULL;
00075     reqblockInfo.id = 0xffffffff;
00076     reqblockPktPtr = NULL;
00077 
00078   };
00079   struct InkBulkIOBlock metablockInfo;
00080   // Location where the next req. block id should be stuffed in the meta block.
00081   uint32_t *metablockReqPtr;
00082   uint32_t metaReqCount;
00083   struct InkBulkIOBlock reqblockInfo;
00084   // Location where the next packet should be stuffed in the req. block
00085   struct InkBulkIOPkt *reqblockPktPtr;
00086   // # of fragments in the last request.
00087   uint32_t lastReqFragCount;
00088   struct InkBulkIORequest *lastReq;
00089   void ResetLastRequestInfo()
00090   {
00091     lastReqFragCount = 0;
00092     lastReq = NULL;
00093     reqblockInfo.ptr = NULL;
00094     reqblockInfo.id = 0xffffffff;
00095     reqblockPktPtr = NULL;
00096   };
00097   void ResetMetaBlockInfo()
00098   {
00099     metaReqCount = 0;
00100     metablockInfo.ptr = NULL;
00101     metablockInfo.id = 0xffffffff;
00102     metablockReqPtr = NULL;
00103   };
00104   bool AppendLastRequest()
00105   {
00106     if (metaReqCount >= INKBIO_MAX_REQS_PER_REQ_BLOCK)
00107       return false;
00108 
00109     memcpy(metablockReqPtr, &(reqblockInfo.id), sizeof(uint32_t));
00110     metablockReqPtr++;
00111     metaReqCount++;
00112     return true;
00113   };
00114   void TerminateMetaBlock()
00115   {
00116     *metablockReqPtr = 0xffffffff;
00117   };
00118   void TerminateLastRequest()
00119   {
00120     reqblockPktPtr->blockID = 0xffffffff;
00121     reqblockPktPtr->pktsize = 0xffff;
00122     reqblockPktPtr->inChain = 0;
00123     reqblockPktPtr->reserved = 0;
00124   };
00125   void InitMetaBlock()
00126   {
00127     metablockReqPtr = (uint32_t *) metablockInfo.ptr;
00128     metaReqCount = 0;
00129   };
00130   void InitSendtoReqBlock()
00131   {
00132     reqblockPktPtr = (struct InkBulkIOPkt *)
00133       ((caddr_t) reqblockInfo.ptr + sizeof(InkBulkIORequest));
00134     lastReq = (struct InkBulkIORequest *) reqblockInfo.ptr;
00135     lastReq->reqType = INKBIO_SENDTO_REQUEST;
00136     lastReq->request.sendto.pktCount = 0;
00137     lastReqFragCount = 0;
00138   };
00139   void InitSplitReqBlock()
00140   {
00141     reqblockPktPtr = (struct InkBulkIOPkt *)
00142       ((caddr_t) reqblockInfo.ptr + sizeof(InkBulkIORequest));
00143     lastReq = (struct InkBulkIORequest *) reqblockInfo.ptr;
00144     lastReq->reqType = INKBIO_SPLIT_REQUEST;
00145     lastReq->request.split.recvCount = 0;
00146     lastReq->request.split.perDestHeader = 0;
00147     lastReqFragCount = 0;
00148   };
00149 
00150 };
00151 
00152 /*
00153  * Initialize the Bulk IO system and create a state cookie
00154  */
00155 struct InkBulkIOState *BulkIOInit(int blockcount);
00156 void BulkIOClose(struct InkBulkIOState *bioCookie);
00157 
00158 int BulkIOBlkAlloc(struct InkBulkIOState *bioCookie, int blkCount, struct InkBulkIOBlock *bioResult);
00159 
00160 int BulkIOAddPkt(struct InkBulkIOState *bioCookie,
00161                  struct InkBulkIOAggregator *bioAggregator, UDPPacketInternal * pkt, int sourcePort);
00162 
00163 int BulkIOSplitPkt(struct InkBulkIOState *bioCookie,
00164                    struct InkBulkIOAggregator *bioAggregator, UDPPacketInternal * pkt, int sourcePort);
00165 
00166 int BulkIOAppendToReqBlock(struct InkBulkIOState *bioCookie,
00167                            struct InkBulkIOAggregator *bioAggregator, Ptr<IOBufferBlock> pkt);
00168 
00169 void BulkIORequestComplete(struct InkBulkIOState *bioCookie, struct InkBulkIOAggregator *bioAggregator);
00170 
00171 void BulkIOFlush(struct InkBulkIOState *bioCookie, struct InkBulkIOAggregator *bioAggregator);
00172 
00173 void CopyFromIOBufferBlock(char *dest, Ptr<IOBufferBlock> pktChain, uint32_t nbytes);
00174 #endif
00175 
00176 #endif

Generated by  doxygen 1.7.1