… | |
… | |
149 | |
149 | |
150 | enum { |
150 | enum { |
151 | REQ_QUIT, |
151 | REQ_QUIT, |
152 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
152 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
153 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
153 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
|
|
154 | REQ_ENV_LOG_ARCHIVE, |
154 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
155 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
155 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
156 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
156 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
157 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
157 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
158 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
158 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
159 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
… | |
… | |
377 | |
378 | |
378 | av_push (av, newSVnv (req->key_range.less)); |
379 | av_push (av, newSVnv (req->key_range.less)); |
379 | av_push (av, newSVnv (req->key_range.equal)); |
380 | av_push (av, newSVnv (req->key_range.equal)); |
380 | av_push (av, newSVnv (req->key_range.greater)); |
381 | av_push (av, newSVnv (req->key_range.greater)); |
381 | |
382 | |
|
|
383 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
384 | |
382 | SvREADONLY_off (req->sv1); |
385 | SvREADONLY_off (req->sv1); |
383 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
386 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
387 | SvREFCNT_dec (av); |
384 | SvREFCNT_dec (req->sv1); |
388 | SvREFCNT_dec (req->sv1); |
385 | } |
389 | } |
386 | break; |
390 | break; |
387 | |
391 | |
388 | #if DB_VERSION_MINOR >= 3 |
392 | #if DB_VERSION_MINOR >= 3 |
… | |
… | |
395 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
399 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
396 | |
400 | |
397 | SvREFCNT_dec (req->sv1); |
401 | SvREFCNT_dec (req->sv1); |
398 | break; |
402 | break; |
399 | #endif |
403 | #endif |
|
|
404 | |
|
|
405 | case REQ_ENV_LOG_ARCHIVE: |
|
|
406 | { |
|
|
407 | AV *av = newAV (); |
|
|
408 | char **listp = (char **)req->buf1; |
|
|
409 | |
|
|
410 | if (listp) |
|
|
411 | while (*listp) |
|
|
412 | av_push (av, newSVpv (*listp, 0)), ++listp; |
|
|
413 | |
|
|
414 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
415 | |
|
|
416 | SvREADONLY_off (req->sv1); |
|
|
417 | sv_setsv_mg (req->sv1, (SV *)av); |
|
|
418 | SvREFCNT_dec (av); |
|
|
419 | SvREFCNT_dec (req->sv1); |
|
|
420 | } |
|
|
421 | break; |
400 | } |
422 | } |
401 | |
423 | |
402 | errno = req->result; |
424 | errno = req->result; |
403 | |
425 | |
404 | if (req->callback) |
426 | if (req->callback) |
… | |
… | |
437 | } |
459 | } |
438 | |
460 | |
439 | #ifdef USE_SOCKETS_AS_HANDLES |
461 | #ifdef USE_SOCKETS_AS_HANDLES |
440 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
462 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
441 | #else |
463 | #else |
|
|
464 | # define EV_SELECT_IS_WINSOCKET 1 |
442 | # define TO_SOCKET(x) (x) |
465 | # define TO_SOCKET(x) (x) |
|
|
466 | #endif |
|
|
467 | |
|
|
468 | #ifdef _WIN32 |
|
|
469 | /* taken verbatim from libev's ev_win32.c */ |
|
|
470 | /* oh, the humanity! */ |
|
|
471 | static int |
|
|
472 | ev_pipe (int filedes [2]) |
|
|
473 | { |
|
|
474 | struct sockaddr_in addr = { 0 }; |
|
|
475 | int addr_size = sizeof (addr); |
|
|
476 | struct sockaddr_in adr2; |
|
|
477 | int adr2_size; |
|
|
478 | SOCKET listener; |
|
|
479 | SOCKET sock [2] = { -1, -1 }; |
|
|
480 | |
|
|
481 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
|
|
482 | return -1; |
|
|
483 | |
|
|
484 | addr.sin_family = AF_INET; |
|
|
485 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
|
486 | addr.sin_port = 0; |
|
|
487 | |
|
|
488 | if (bind (listener, (struct sockaddr *)&addr, addr_size)) |
|
|
489 | goto fail; |
|
|
490 | |
|
|
491 | if (getsockname (listener, (struct sockaddr *)&addr, &addr_size)) |
|
|
492 | goto fail; |
|
|
493 | |
|
|
494 | if (listen (listener, 1)) |
|
|
495 | goto fail; |
|
|
496 | |
|
|
497 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
|
|
498 | goto fail; |
|
|
499 | |
|
|
500 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
|
|
501 | goto fail; |
|
|
502 | |
|
|
503 | if ((sock [1] = accept (listener, 0, 0)) < 0) |
|
|
504 | goto fail; |
|
|
505 | |
|
|
506 | /* windows vista returns fantasy port numbers for getpeername. |
|
|
507 | * example for two interconnected tcp sockets: |
|
|
508 | * |
|
|
509 | * (Socket::unpack_sockaddr_in getsockname $sock0)[0] == 53364 |
|
|
510 | * (Socket::unpack_sockaddr_in getpeername $sock0)[0] == 53363 |
|
|
511 | * (Socket::unpack_sockaddr_in getsockname $sock1)[0] == 53363 |
|
|
512 | * (Socket::unpack_sockaddr_in getpeername $sock1)[0] == 53365 |
|
|
513 | * |
|
|
514 | * wow! tridirectional sockets! |
|
|
515 | * |
|
|
516 | * this way of checking ports seems to work: |
|
|
517 | */ |
|
|
518 | if (getpeername (sock [0], (struct sockaddr *)&addr, &addr_size)) |
|
|
519 | goto fail; |
|
|
520 | |
|
|
521 | if (getsockname (sock [1], (struct sockaddr *)&adr2, &adr2_size)) |
|
|
522 | goto fail; |
|
|
523 | |
|
|
524 | errno = WSAEINVAL; |
|
|
525 | if (addr_size != adr2_size |
|
|
526 | || addr.sin_addr.s_addr != adr2.sin_addr.s_addr /* just to be sure, I mean, it's windows */ |
|
|
527 | || addr.sin_port != adr2.sin_port) |
|
|
528 | goto fail; |
|
|
529 | |
|
|
530 | closesocket (listener); |
|
|
531 | |
|
|
532 | #if EV_SELECT_IS_WINSOCKET |
|
|
533 | filedes [0] = _open_osfhandle (sock [0], 0); |
|
|
534 | filedes [1] = _open_osfhandle (sock [1], 0); |
|
|
535 | #else |
|
|
536 | /* when select isn't winsocket, we also expect socket, connect, accept etc. |
|
|
537 | * to work on fds */ |
|
|
538 | filedes [0] = sock [0]; |
|
|
539 | filedes [1] = sock [1]; |
|
|
540 | #endif |
|
|
541 | |
|
|
542 | return 0; |
|
|
543 | |
|
|
544 | fail: |
|
|
545 | closesocket (listener); |
|
|
546 | |
|
|
547 | if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); |
|
|
548 | if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); |
|
|
549 | |
|
|
550 | return -1; |
|
|
551 | } |
443 | #endif |
552 | #endif |
444 | |
553 | |
445 | static void |
554 | static void |
446 | create_respipe (void) |
555 | create_respipe (void) |
447 | { |
556 | { |
… | |
… | |
452 | |
561 | |
453 | if (respipe [1] >= 0) |
562 | if (respipe [1] >= 0) |
454 | respipe_close (TO_SOCKET (respipe [1])); |
563 | respipe_close (TO_SOCKET (respipe [1])); |
455 | |
564 | |
456 | #ifdef _WIN32 |
565 | #ifdef _WIN32 |
457 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
566 | if (ev_pipe (respipe)) |
458 | #else |
567 | #else |
459 | if (pipe (respipe)) |
568 | if (pipe (respipe)) |
460 | #endif |
569 | #endif |
461 | croak ("unable to initialize result pipe"); |
570 | croak ("unable to initialize result pipe"); |
462 | |
571 | |
… | |
… | |
869 | |
978 | |
870 | case REQ_SEQ_REMOVE: |
979 | case REQ_SEQ_REMOVE: |
871 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
980 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
872 | break; |
981 | break; |
873 | #endif |
982 | #endif |
|
|
983 | |
|
|
984 | case REQ_ENV_LOG_ARCHIVE: |
|
|
985 | { |
|
|
986 | char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */ |
|
|
987 | req->result = req->env->log_archive (req->env, &listp, req->uint1); |
|
|
988 | req->buf1 = (char *)listp; |
|
|
989 | } |
|
|
990 | break; |
874 | |
991 | |
875 | default: |
992 | default: |
876 | req->result = ENOSYS; |
993 | req->result = ENOSYS; |
877 | break; |
994 | break; |
878 | } |
995 | } |
… | |
… | |
1132 | } |
1249 | } |
1133 | } |
1250 | } |
1134 | |
1251 | |
1135 | return 0; |
1252 | return 0; |
1136 | } |
1253 | } |
|
|
1254 | |
|
|
1255 | /*****************************************************************************/ |
|
|
1256 | |
|
|
1257 | #if 0 |
|
|
1258 | static int |
|
|
1259 | bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1260 | { |
|
|
1261 | ssize_t size1 = dbt1->size; |
|
|
1262 | ssize_t size2 = dbt2->size; |
|
|
1263 | int res = memcmp ((void *)dbt1->data, (void *)dbt2->data, |
|
|
1264 | size1 <= size2 ? size1 : size2); |
|
|
1265 | |
|
|
1266 | if (res) |
|
|
1267 | return res; |
|
|
1268 | else if (size1 - size2) |
|
|
1269 | return size1 - size2; |
|
|
1270 | else |
|
|
1271 | return 0; |
|
|
1272 | } |
|
|
1273 | |
|
|
1274 | static size_t |
|
|
1275 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1276 | { |
|
|
1277 | ssize_t size1 = dbt1->size; |
|
|
1278 | ssize_t size2 = dbt2->size; |
|
|
1279 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1280 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1281 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1282 | |
|
|
1283 | while (p1 < pe) |
|
|
1284 | if (*p1++ != *p2++) |
|
|
1285 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1286 | |
|
|
1287 | if (size1 < size2) return size1 + 1; |
|
|
1288 | if (size1 > size2) return size2 + 1; |
|
|
1289 | |
|
|
1290 | return size1; |
|
|
1291 | } |
|
|
1292 | #endif |
|
|
1293 | |
|
|
1294 | /*****************************************************************************/ |
1137 | |
1295 | |
1138 | /* stupid windows defines CALLBACK as well */ |
1296 | /* stupid windows defines CALLBACK as well */ |
1139 | #undef CALLBACK |
1297 | #undef CALLBACK |
1140 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1298 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1141 | |
1299 | |
… | |
… | |
1278 | const_iv (REP_UNAVAIL) |
1436 | const_iv (REP_UNAVAIL) |
1279 | const_iv (RUNRECOVERY) |
1437 | const_iv (RUNRECOVERY) |
1280 | const_iv (SECONDARY_BAD) |
1438 | const_iv (SECONDARY_BAD) |
1281 | const_iv (VERIFY_BAD) |
1439 | const_iv (VERIFY_BAD) |
1282 | |
1440 | |
|
|
1441 | const_iv (ARCH_ABS) |
|
|
1442 | const_iv (ARCH_DATA) |
|
|
1443 | const_iv (ARCH_LOG) |
|
|
1444 | const_iv (ARCH_REMOVE) |
|
|
1445 | |
1283 | const_iv (VERB_DEADLOCK) |
1446 | const_iv (VERB_DEADLOCK) |
1284 | const_iv (VERB_RECOVERY) |
1447 | const_iv (VERB_RECOVERY) |
1285 | const_iv (VERB_REPLICATION) |
1448 | const_iv (VERB_REPLICATION) |
1286 | const_iv (VERB_WAITSFOR) |
1449 | const_iv (VERB_WAITSFOR) |
1287 | |
1450 | |
… | |
… | |
1320 | const_iv (PRIORITY_VERY_LOW) |
1483 | const_iv (PRIORITY_VERY_LOW) |
1321 | const_iv (PRIORITY_LOW) |
1484 | const_iv (PRIORITY_LOW) |
1322 | const_iv (PRIORITY_DEFAULT) |
1485 | const_iv (PRIORITY_DEFAULT) |
1323 | const_iv (PRIORITY_HIGH) |
1486 | const_iv (PRIORITY_HIGH) |
1324 | const_iv (PRIORITY_VERY_HIGH) |
1487 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1488 | const_iv (IGNORE_LEASE) |
1325 | #endif |
1489 | #endif |
1326 | #if DB_VERSION_MINOR >= 7 |
1490 | #if DB_VERSION_MINOR >= 7 |
1327 | const_iv (IGNORE_LEASE) |
|
|
1328 | //const_iv (MULTIPLE_KEY) |
1491 | //const_iv (MULTIPLE_KEY) |
1329 | const_iv (LOG_DIRECT) |
1492 | const_iv (LOG_DIRECT) |
1330 | const_iv (LOG_DSYNC) |
1493 | const_iv (LOG_DSYNC) |
1331 | const_iv (LOG_AUTO_REMOVE) |
1494 | const_iv (LOG_AUTO_REMOVE) |
1332 | const_iv (LOG_IN_MEMORY) |
1495 | const_iv (LOG_IN_MEMORY) |
… | |
… | |
1637 | req->buf3 = strdup_ornull (newname); |
1800 | req->buf3 = strdup_ornull (newname); |
1638 | req->uint1 = flags; |
1801 | req->uint1 = flags; |
1639 | REQ_SEND; |
1802 | REQ_SEND; |
1640 | } |
1803 | } |
1641 | |
1804 | |
|
|
1805 | void |
|
|
1806 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1807 | PREINIT: |
|
|
1808 | CALLBACK |
|
|
1809 | CODE: |
|
|
1810 | { |
|
|
1811 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1812 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1813 | req->env = env; |
|
|
1814 | req->uint1 = flags; |
|
|
1815 | REQ_SEND; |
|
|
1816 | } |
|
|
1817 | |
1642 | DB * |
1818 | DB * |
1643 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1819 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1644 | CODE: |
1820 | CODE: |
1645 | { |
1821 | { |
1646 | errno = db_create (&RETVAL, env, flags); |
1822 | errno = db_create (&RETVAL, env, flags); |