File: btrequest.h

package info (click to toggle)
ctorrent 1.3.4.dnh3.3.2-5
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,240 kB
  • sloc: cpp: 13,161; sh: 675; ansic: 383; makefile: 6
file content (92 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef SLICE_H
#define SLICE_H

#include "def.h"

#include <sys/types.h>
#include <time.h>
#include "btcontent.h"
#include "bitfield.h"

typedef struct _slice{
   size_t index;
   size_t offset;
   size_t length;
   time_t reqtime;
   struct _slice *next;
}SLICE,*PSLICE;

class RequestQueue
{
 private:
  PSLICE rq_head;
 public:
  PSLICE rq_send;  // next slice to request

  RequestQueue();
  ~RequestQueue();

  void Empty();

  void SetHead(PSLICE ps);
  void SetNextSend(PSLICE ps) { rq_send = ps; }
  PSLICE GetHead() const { return rq_head; }
  PSLICE NextSend() const { return rq_send; }
  size_t GetRequestIdx() const { return rq_head ? rq_head->index :
                                                  BTCONTENT.GetNPieces(); }
  size_t GetRequestLen() const { return rq_head ? rq_head->length : 0; }
  void Release(){ rq_head = rq_send = (PSLICE) 0; }
  int IsValidRequest(size_t idx,size_t off,size_t len) const;

  void operator=(RequestQueue &rq);
  int Copy(const RequestQueue *prq, size_t idx);
  int CopyShuffle(const RequestQueue *prq, size_t idx);
  size_t Qsize() const;
  size_t Qlen(size_t piece) const;
  int LastSlice() const;

  int IsEmpty() const { return rq_head ? 0 : 1; }

  int Insert(PSLICE ps,size_t idx,size_t off,size_t len);
  int Add(size_t idx,size_t off,size_t len);
  int Append(PSLICE ps);
  int Remove(size_t idx,size_t off,size_t len);
  int Requeue(size_t idx,size_t off,size_t len);
  void MoveLast(PSLICE ps);
  int HasIdx(size_t idx) const;
  int HasSlice(size_t idx, size_t off, size_t len) const;
  time_t GetReqTime(size_t idx,size_t off,size_t len) const;
  void SetReqTime(PSLICE n,time_t t);


  int Pop(size_t *pidx,size_t *poff,size_t *plen);
  int Peek(size_t *pidx,size_t *poff,size_t *plen) const;

  int CreateWithIdx(size_t idx);
  size_t NSlices(size_t idx) const;
  size_t Slice_Length(size_t idx,size_t sidx) const;
};

#define PENDING_QUEUE_SIZE 100

class PendingQueue
{
 private:
  PSLICE pending_array[PENDING_QUEUE_SIZE];
  size_t pq_count;
  
 public:
  PendingQueue();
  ~PendingQueue();
  void Empty();
  int Pending(RequestQueue *prq);
  size_t ReAssign(RequestQueue *prq, BitField &bf);
  int Exist(size_t idx) const;
  int HasSlice(size_t idx, size_t off, size_t len);
  int Delete(size_t idx);
  int DeleteSlice(size_t idx, size_t off, size_t len);
};

extern PendingQueue PENDINGQUEUE;

#endif