~ubuntu-branches/debian/experimental/libtorrent/experimental

« back to all changes in this revision

Viewing changes to src/data/socket_file.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-03-31 10:31:05 UTC
  • mto: (4.1.4 gutsy) (6.2.1 squeeze) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070331103105-jzpp1rml6ud0ff75
Tags: upstream-0.11.4
ImportĀ upstreamĀ versionĀ 0.11.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
namespace torrent {
54
54
 
55
 
SocketFile::~SocketFile() {
56
 
  // Temporary test case to make sure we close files properly.
57
 
  if (is_open())
58
 
    throw internal_error("Destroyed a SocketFile that is open");
59
 
}
60
 
 
61
55
bool
62
56
SocketFile::open(const std::string& path, int prot, int flags, mode_t mode) {
63
57
  close();
82
76
    return false;
83
77
 
84
78
  m_fd = fd;
85
 
  m_flags = flags;
86
 
  m_prot = prot;
87
 
 
88
79
  return true;
89
80
}
90
81
 
96
87
  ::close(m_fd);
97
88
 
98
89
  m_fd = invalid_fd;
99
 
  m_prot = 0;
100
 
  m_flags = 0;
101
90
}
102
91
 
103
92
// Reserve the space on disk if a system call is defined. 'length'
109
98
#endif
110
99
 
111
100
bool
112
 
SocketFile::reserve(RESERVE_PARAM off_t offset, RESERVE_PARAM off_t length) {
 
101
SocketFile::reserve(RESERVE_PARAM uint64_t offset, RESERVE_PARAM uint64_t length) {
113
102
#ifdef USE_XFS
114
103
  struct xfs_flock64 flock;
115
104
 
130
119
 
131
120
#undef RESERVE_PARAM
132
121
 
133
 
off_t
 
122
uint64_t
134
123
SocketFile::size() const {
135
124
  if (!is_open())
136
125
    throw internal_error("SocketFile::size() called on a closed file");
141
130
}  
142
131
 
143
132
bool
144
 
SocketFile::set_size(off_t size) const {
 
133
SocketFile::set_size(uint64_t size) const {
145
134
  if (!is_open())
146
135
    throw internal_error("SocketFile::set_size() called on a closed file");
147
136
 
152
141
  // client to block while it is resizing the files, this really
153
142
  // should be in a seperate thread.
154
143
  if (size != 0 &&
155
 
      lseek(m_fd, size - 1, SEEK_SET) == (size - 1) &&
 
144
      lseek(m_fd, size - 1, SEEK_SET) == (off_t)(size - 1) &&
156
145
      write(m_fd, &size, 1) == 1)
157
146
    return true;
158
147
  
160
149
}
161
150
 
162
151
MemoryChunk
163
 
SocketFile::create_chunk(off_t offset, uint32_t length, int prot, int flags) const {
 
152
SocketFile::create_chunk(uint64_t offset, uint32_t length, int prot, int flags) const {
164
153
  if (!is_open())
165
154
    throw internal_error("SocketFile::get_chunk() called on a closed file");
166
155
 
167
 
  if (((prot & MemoryChunk::prot_read) && !is_readable()) ||
168
 
      ((prot & MemoryChunk::prot_write) && !is_writable()))
169
 
    throw storage_error("SocketFile::get_chunk() permission denied");
170
 
 
171
156
  // For some reason mapping beyond the extent of the file does not
172
157
  // cause mmap to complain, so we need to check manually here.
173
158
  if (offset < 0 || length == 0 || offset > size() || offset + length > size())
174
159
    return MemoryChunk();
175
160
 
176
 
  off_t align = offset % MemoryChunk::page_size();
 
161
  uint64_t align = offset % MemoryChunk::page_size();
177
162
 
178
163
  char* ptr = (char*)mmap(NULL, length + align, prot, flags, m_fd, offset - align);
179
164