Ticket #242: patch7.patch

File patch7.patch, 3.8 KB (added by Charlie Hull, 16 years ago)

Patch to make replicate1 test pass on Windows

  • common/utils.cc

     
    149149        while (true) {
    150150            errno = 0;
    151151            struct dirent * entry = readdir(dir);
     152            int tmp =errno;
    152153            if (entry == NULL) {
    153                 if (errno == 0)
     154                if ((errno == 0) || (errno == ENOENT))
    154155                    break;
    155156                throw Xapian::DatabaseError("Cannot read entry from directory at '" + dirname + "'", errno);
    156157            }
  • net/remoteconnection.cc

     
    7878    if (buffer.length() >= min_len) return;
    7979
    8080#ifdef __WIN32__
     81    // FIXME transforming handles this way isn't recommended. In particular
     82    // file offsets are not preserved through subsequent ReadFile calls, so
     83    // we have to do this manually (although this will only manifest when using
     84    // an actual file)
    8185    HANDLE hin = fd_to_handle(fdin);
     86    off_t ofs;
    8287    do {
    8388        char buf[CHUNKSIZE];
    8489        DWORD received;
     
    104109            throw Xapian::NetworkError("Received EOF", context);
    105110
    106111        buffer.append(buf, received);
     112
     113        // We must move the offset in the OVERLAPPED structure manually
     114        ofs = (((off_t)overlapped.OffsetHigh)<<32) + overlapped.Offset + received;
     115        overlapped.Offset = ofs & 0xFFFFFFFF;
     116        overlapped.OffsetHigh = ofs >> 32;
     117
    107118    } while (buffer.length() < min_len);
    108119#else
    109120    // If there's no end_time, just use blocking I/O.
     
    196207    header += encode_length(message.size());
    197208
    198209#ifdef __WIN32__
     210    // FIXME transforming handles this way isn't recommended. In particular
     211    // file offsets are not preserved through subsequent WriteFile calls, so
     212    // we have to do this manually (although this will only manifest when using
     213    // an actual file)
    199214    HANDLE hout = fd_to_handle(fdout);
    200215    const string * str = &header;
     216    off_t ofs;
    201217
    202218    size_t count = 0;
    203219    while (true) {
     
    221237        }
    222238
    223239        count += n;
     240
     241        // We must move the offset in the OVERLAPPED structure manually
     242        ofs = (((off_t)overlapped.OffsetHigh)<<32) + overlapped.Offset + n;
     243        overlapped.Offset = ofs & 0xFFFFFFFF;
     244        overlapped.OffsetHigh = ofs >> 32;
     245
    224246        if (count == str->size()) {
    225247            if (str == &message || message.empty()) return;
    226248            str = &message;
    227249            count = 0;
    228250        }
     251
    229252    }
     253
     254
    230255#else
    231256    // If there's no end_time, just use blocking I/O.
    232257    if (fcntl(fdout, F_SETFL, end_time.is_set() ? O_NONBLOCK : 0) < 0) {
     
    325350    }
    326351
    327352#ifdef __WIN32__
     353    // FIXME transforming handles this way isn't recommended. In particular
     354    // file offsets are not preserved through subsequent WriteFile calls, so
     355    // we have to do this manually (although this will only manifest when using
     356    // an actual file)
    328357    HANDLE hout = fd_to_handle(fdout);
    329 
     358    off_t ofs;
    330359    size_t count = 0;
    331360    while (true) {
    332361        DWORD n;
     
    349378        }
    350379
    351380        count += n;
     381
     382        // We must move the offset in the OVERLAPPED structure manually
     383        ofs = (((off_t)overlapped.OffsetHigh)<<32) + overlapped.Offset + n;
     384        overlapped.Offset = ofs & 0xFFFFFFFF;
     385        overlapped.OffsetHigh = ofs >> 32;
     386
    352387        if (count == c) {
    353388            if (size == 0) return;
    354389
     
    363398            count = 0;
    364399        }
    365400    }
     401   
    366402#else
    367403    // If there's no end_time, just use blocking I/O.
    368404    if (fcntl(fdout, F_SETFL, end_time.is_set() ? O_NONBLOCK : 0) < 0) {
  • tests/api_replicate.cc

     
    175175
    176176    check_equal_dbs(masterpath, replicapath);
    177177
     178    replica.close();
    178179    rmtmpdir(tempdir);
    179180    return true;
    180181}