179
179
priority.schedule(PRIORITY_HIGH);
183
Sync sync(&syncObject, "SerialLogFile::write");
184
sync.lock(Exclusive);
186
if (position != offset)
189
pos.QuadPart = position;
191
if (!SetFilePointerEx(handle, pos, NULL, FILE_BEGIN))
192
throw SQLError(IO_ERROR, "serial log SetFilePointerEx failed with %d", GetLastError());
183
pos.QuadPart = position;
184
OVERLAPPED overlapped = {0};
185
overlapped.Offset = pos.LowPart;
186
overlapped.OffsetHigh = pos.HighPart;
197
if (!WriteFile(handle, data, effectiveLength, &ret, NULL))
190
if (!WriteFile(handle, data, effectiveLength, &ret, &overlapped))
199
192
int lastError = GetLastError();
219
212
if (loc != position)
220
213
throw SQLEXCEPTION (IO_ERROR, "serial lseek error on \"%s\": %s (%d)",
221
214
(const char*) fileName, strerror (errno), errno);
225
217
uint32 n = ::write(handle, data, effectiveLength);
231
224
if (n != effectiveLength)
259
252
priority.schedule(PRIORITY_HIGH);
262
Sync sync(&syncObject, "SerialLogFile::read");
263
sync.lock(Exclusive);
264
256
ASSERT(position < writePoint || writePoint == 0);
265
257
LARGE_INTEGER pos;
266
258
pos.QuadPart = position;
268
if (!SetFilePointerEx(handle, pos, NULL, FILE_BEGIN))
269
throw SQLError(IO_ERROR, "serial log SetFilePointer failed with %d", GetLastError());
259
OVERLAPPED overlapped = {0};
260
overlapped.Offset = pos.LowPart;
261
overlapped.OffsetHigh = pos.HighPart;
273
if (!ReadFile(handle, data, effectiveLength, &ret, NULL))
265
if (!ReadFile(handle, data, effectiveLength, &ret, &overlapped))
274
266
throw SQLError(IO_ERROR, "serial log ReadFile failed with %d", GetLastError());
276
268
offset = position + effectiveLength;
300
void SerialLogFile::truncate(int64 size)
303
LARGE_INTEGER oldPos, distance;
304
distance.QuadPart = 0;
306
// Get current position in file
307
if (!SetFilePointerEx(handle, distance ,&oldPos,FILE_CURRENT))
308
throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d",
311
// Position to the new end of file , set EOF marker there
312
distance.QuadPart = size;
313
if (!SetFilePointerEx(handle, distance, 0, FILE_BEGIN))
314
throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d",
317
if (!SetEndOfFile(handle))
318
throw SQLError(IO_ERROR, "SetEndOfFile failed with %d",
322
// Restore file pointer
323
if (!SetFilePointerEx(handle, oldPos ,0,FILE_BEGIN))
324
throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d",
327
if (ftruncate(handle, size))
328
throw SQLError(IO_ERROR, "ftruncate failed with %d",
333
int64 SerialLogFile::size(void)
338
if (!GetFileSizeEx(handle, &size))
339
throw SQLError(IO_ERROR, "GetFileSizeEx failed with %u",
342
return size.QuadPart;
345
if (fstat(handle, &buf))
346
throw SQLError(IO_ERROR, "stat failed with %d",
309
352
void SerialLogFile::zap()