ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.64 by root, Wed Nov 12 16:52:51 2008 UTC vs.
Revision 1.68 by root, Tue Jul 14 19:29:23 2009 UTC

5#include <errno.h> 5#include <errno.h>
6 6
7#include "EXTERN.h" 7#include "EXTERN.h"
8#include "perl.h" 8#include "perl.h"
9#include "XSUB.h" 9#include "XSUB.h"
10
11#include "schmorp.h"
10 12
11// perl stupidly defines these as macros, breaking 13// perl stupidly defines these as macros, breaking
12// lots and lots of code. 14// lots and lots of code.
13#undef open 15#undef open
14#undef close 16#undef close
150enum { 152enum {
151 REQ_QUIT, 153 REQ_QUIT,
152 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 154 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, 155 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME,
154 REQ_ENV_LOG_ARCHIVE, 156 REQ_ENV_LOG_ARCHIVE,
155 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, 157 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE,
156 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 158 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
157 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, 159 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
158 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 160 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
159 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 161 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
160}; 162};
456 free (req->buf3); 458 free (req->buf3);
457 459
458 Safefree (req); 460 Safefree (req);
459} 461}
460 462
461#ifdef USE_SOCKETS_AS_HANDLES
462# define TO_SOCKET(x) (win32_get_osfhandle (x))
463#else
464# define TO_SOCKET(x) (x)
465#endif
466
467static void 463static void
468create_respipe (void) 464create_respipe (void)
469{ 465{
470#ifdef _WIN32 466#ifdef _WIN32
471 int arg; /* argg */ 467 int arg; /* argg */
472#endif 468#endif
473 int old_readfd = respipe [0]; 469 int old_readfd = respipe [0];
474 470
475 if (respipe [1] >= 0) 471 if (respipe [1] >= 0)
476 respipe_close (TO_SOCKET (respipe [1])); 472 respipe_close (S_TO_SOCKET (respipe [1]));
477 473
478#ifdef _WIN32
479 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
480#else
481 if (pipe (respipe)) 474 if (s_pipe (respipe))
482#endif
483 croak ("unable to initialize result pipe"); 475 croak ("unable to initialize result pipe");
484 476
485 if (old_readfd >= 0) 477 if (old_readfd >= 0)
486 { 478 {
487 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) 479 if (dup2 (S_TO_SOCKET (respipe [0]), S_TO_SOCKET (old_readfd)) < 0)
488 croak ("unable to initialize result pipe(2)"); 480 croak ("unable to initialize result pipe(2)");
489 481
490 respipe_close (respipe [0]); 482 respipe_close (respipe [0]);
491 respipe [0] = old_readfd; 483 respipe [0] = old_readfd;
492 } 484 }
493 485
494#ifdef _WIN32 486#ifdef _WIN32
495 arg = 1; 487 arg = 1;
496 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) 488 if (ioctlsocket (S_TO_SOCKET (respipe [0]), FIONBIO, &arg)
497 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) 489 || ioctlsocket (S_TO_SOCKET (respipe [1]), FIONBIO, &arg))
498#else 490#else
499 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) 491 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
500 || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) 492 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
501#endif 493#endif
502 croak ("unable to initialize result pipe(3)"); 494 croak ("unable to initialize result pipe(3)");
503 495
504 respipe_osf [0] = TO_SOCKET (respipe [0]); 496 respipe_osf [0] = S_TO_SOCKET (respipe [0]);
505 respipe_osf [1] = TO_SOCKET (respipe [1]); 497 respipe_osf [1] = S_TO_SOCKET (respipe [1]);
506} 498}
507 499
508static void bdb_request (bdb_req req); 500static void bdb_request (bdb_req req);
509X_THREAD_PROC (bdb_proc); 501X_THREAD_PROC (bdb_proc);
510 502
796 break; 788 break;
797#endif 789#endif
798 790
799 case REQ_DB_SYNC: 791 case REQ_DB_SYNC:
800 req->result = req->db->sync (req->db, req->uint1); 792 req->result = req->db->sync (req->db, req->uint1);
793 break;
794
795 case REQ_DB_VERIFY:
796 req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1);
801 break; 797 break;
802 798
803 case REQ_DB_UPGRADE: 799 case REQ_DB_UPGRADE:
804 req->result = req->db->upgrade (req->db, req->buf1, req->uint1); 800 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
805 break; 801 break;
1349 const_iv (REP_UNAVAIL) 1345 const_iv (REP_UNAVAIL)
1350 const_iv (RUNRECOVERY) 1346 const_iv (RUNRECOVERY)
1351 const_iv (SECONDARY_BAD) 1347 const_iv (SECONDARY_BAD)
1352 const_iv (VERIFY_BAD) 1348 const_iv (VERIFY_BAD)
1353 1349
1350 const_iv (SALVAGE)
1351 const_iv (AGGRESSIVE)
1352 const_iv (PRINTABLE)
1353 const_iv (NOORDERCHK)
1354 const_iv (ORDERCHKONLY)
1355
1354 const_iv (ARCH_ABS) 1356 const_iv (ARCH_ABS)
1355 const_iv (ARCH_DATA) 1357 const_iv (ARCH_DATA)
1356 const_iv (ARCH_LOG) 1358 const_iv (ARCH_LOG)
1357 const_iv (ARCH_REMOVE) 1359 const_iv (ARCH_REMOVE)
1358 1360
1803 req->uint1 = flags; 1805 req->uint1 = flags;
1804 REQ_SEND; 1806 REQ_SEND;
1805} 1807}
1806 1808
1807void 1809void
1810db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0)
1811 PREINIT:
1812 CALLBACK
1813 CODE:
1814{
1815 dREQ (REQ_DB_VERIFY, 1);
1816 ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */
1817 req->db = db;
1818 req->buf1 = strdup (file);
1819 req->buf2 = strdup_ornull (database);
1820 req->uint1 = flags;
1821 REQ_SEND;
1822}
1823
1824void
1808db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) 1825db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1809 PREINIT: 1826 PREINIT:
1810 CALLBACK 1827 CALLBACK
1811 CODE: 1828 CODE:
1812{ 1829{
1813 dREQ (REQ_DB_SYNC, 1); 1830 dREQ (REQ_DB_UPGRADE, 1);
1814 req->db = db; 1831 req->db = db;
1815 req->buf1 = strdup (file); 1832 req->buf1 = strdup (file);
1816 req->uint1 = flags; 1833 req->uint1 = flags;
1817 REQ_SEND; 1834 REQ_SEND;
1818} 1835}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines