… | |
… | |
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 | |
10 | |
|
|
11 | #include "schmorp.h" |
|
|
12 | |
11 | // perl stupidly defines these as macros, breaking |
13 | // perl stupidly defines these as argument-less 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 |
15 | #undef abort |
17 | #undef abort |
16 | #undef malloc |
18 | #undef malloc |
… | |
… | |
29 | # include <unistd.h> |
31 | # include <unistd.h> |
30 | #endif |
32 | #endif |
31 | |
33 | |
32 | #include <db.h> |
34 | #include <db.h> |
33 | |
35 | |
34 | #if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) |
36 | #define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR |
|
|
37 | |
|
|
38 | #if DBVER < 403 |
35 | # error you need Berkeley DB 4.3 or a newer 4.x version installed |
39 | # error you need Berkeley DB 4.3 or a newer version installed |
36 | #endif |
40 | #endif |
37 | |
41 | |
38 | /* number of seconds after which idle threads exit */ |
42 | /* number of seconds after which idle threads exit */ |
39 | #define IDLE_TIMEOUT 10 |
43 | #define IDLE_TIMEOUT 10 |
40 | |
44 | |
… | |
… | |
48 | typedef DB_ENV DB_ENV_ornuked; |
52 | typedef DB_ENV DB_ENV_ornuked; |
49 | typedef DB_TXN DB_TXN_ornuked; |
53 | typedef DB_TXN DB_TXN_ornuked; |
50 | typedef DBC DBC_ornuked; |
54 | typedef DBC DBC_ornuked; |
51 | typedef DB DB_ornuked; |
55 | typedef DB DB_ornuked; |
52 | |
56 | |
53 | #if DB_VERSION_MINOR >= 3 |
57 | #if DBVER >= 403 |
54 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
58 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
55 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
59 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
56 | #endif |
60 | #endif |
57 | |
61 | |
58 | typedef char *bdb_filename; |
62 | typedef char *bdb_filename; |
59 | |
63 | |
60 | static SV *prepare_cb; |
64 | static SV *prepare_cb; |
61 | |
65 | |
62 | #if DB_VERSION_MINOR >= 6 |
66 | static HV |
|
|
67 | *bdb_stash, |
|
|
68 | *bdb_env_stash, |
|
|
69 | *bdb_txn_stash, |
|
|
70 | *bdb_cursor_stash, |
|
|
71 | *bdb_db_stash, |
|
|
72 | *bdb_sequence_stash; |
|
|
73 | |
|
|
74 | #if DBVER >= 406 |
63 | # define c_close close |
75 | # define c_close close |
64 | # define c_count count |
76 | # define c_count count |
65 | # define c_del del |
77 | # define c_del del |
66 | # define c_dup dup |
78 | # define c_dup dup |
67 | # define c_get get |
79 | # define c_get get |
… | |
… | |
176 | char *buf1, *buf2, *buf3; |
188 | char *buf1, *buf2, *buf3; |
177 | SV *sv1, *sv2, *sv3; |
189 | SV *sv1, *sv2, *sv3; |
178 | |
190 | |
179 | DBT dbt1, dbt2, dbt3; |
191 | DBT dbt1, dbt2, dbt3; |
180 | DB_KEY_RANGE key_range; |
192 | DB_KEY_RANGE key_range; |
181 | #if DB_VERSION_MINOR >= 3 |
193 | #if DBVER >= 403 |
182 | DB_SEQUENCE *seq; |
194 | DB_SEQUENCE *seq; |
183 | db_seq_t seq_t; |
195 | db_seq_t seq_t; |
184 | #endif |
196 | #endif |
185 | |
197 | |
186 | SV *rsv1, *rsv2; // keep some request objects alive |
198 | SV *rsv1, *rsv2; // keep some request objects alive |
… | |
… | |
214 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
226 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
215 | |
227 | |
216 | static unsigned int started, idle, wanted; |
228 | static unsigned int started, idle, wanted; |
217 | |
229 | |
218 | /* worker threads management */ |
230 | /* worker threads management */ |
219 | static mutex_t wrklock = X_MUTEX_INIT; |
231 | static xmutex_t wrklock = X_MUTEX_INIT; |
220 | |
232 | |
221 | typedef struct worker { |
233 | typedef struct worker { |
222 | /* locked by wrklock */ |
234 | /* locked by wrklock */ |
223 | struct worker *prev, *next; |
235 | struct worker *prev, *next; |
224 | |
236 | |
225 | thread_t tid; |
237 | xthread_t tid; |
226 | |
238 | |
227 | /* locked by reslock, reqlock or wrklock */ |
239 | /* locked by reslock, reqlock or wrklock */ |
228 | bdb_req req; /* currently processed request */ |
240 | bdb_req req; /* currently processed request */ |
229 | void *dbuf; |
241 | void *dbuf; |
230 | DIR *dirp; |
242 | DIR *dirp; |
… | |
… | |
245 | } |
257 | } |
246 | |
258 | |
247 | static volatile unsigned int nreqs, nready, npending; |
259 | static volatile unsigned int nreqs, nready, npending; |
248 | static volatile unsigned int max_idle = 4; |
260 | static volatile unsigned int max_idle = 4; |
249 | static volatile unsigned int max_outstanding = 0xffffffff; |
261 | static volatile unsigned int max_outstanding = 0xffffffff; |
250 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
262 | static s_epipe respipe; |
251 | |
263 | |
252 | static mutex_t reslock = X_MUTEX_INIT; |
264 | static xmutex_t reslock = X_MUTEX_INIT; |
253 | static mutex_t reqlock = X_MUTEX_INIT; |
265 | static xmutex_t reqlock = X_MUTEX_INIT; |
254 | static cond_t reqwait = X_COND_INIT; |
266 | static xcond_t reqwait = X_COND_INIT; |
255 | |
267 | |
256 | #if WORDACCESS_UNSAFE |
268 | #if WORDACCESS_UNSAFE |
257 | |
269 | |
258 | static unsigned int get_nready (void) |
270 | static unsigned int get_nready (void) |
259 | { |
271 | { |
… | |
… | |
387 | SvREFCNT_dec (av); |
399 | SvREFCNT_dec (av); |
388 | SvREFCNT_dec (req->sv1); |
400 | SvREFCNT_dec (req->sv1); |
389 | } |
401 | } |
390 | break; |
402 | break; |
391 | |
403 | |
392 | #if DB_VERSION_MINOR >= 3 |
404 | #if DBVER >= 403 |
393 | case REQ_SEQ_GET: |
405 | case REQ_SEQ_GET: |
394 | SvREADONLY_off (req->sv1); |
406 | SvREADONLY_off (req->sv1); |
395 | |
407 | |
396 | if (sizeof (IV) > 4) |
408 | if (sizeof (IV) > 4) |
397 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
409 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
… | |
… | |
456 | free (req->buf3); |
468 | free (req->buf3); |
457 | |
469 | |
458 | Safefree (req); |
470 | Safefree (req); |
459 | } |
471 | } |
460 | |
472 | |
461 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
462 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
463 | #else |
|
|
464 | # define EV_SELECT_IS_WINSOCKET 1 |
|
|
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 | } |
|
|
552 | |
|
|
553 | #define pipe(filedes) ev_pipe(filedes) |
|
|
554 | #endif |
|
|
555 | |
|
|
556 | static void |
473 | static void |
557 | create_respipe (void) |
474 | create_respipe (void) |
558 | { |
475 | { |
559 | #ifdef _WIN32 |
|
|
560 | int arg; /* argg */ |
|
|
561 | #endif |
|
|
562 | int old_readfd = respipe [0]; |
|
|
563 | |
|
|
564 | if (respipe [1] >= 0) |
|
|
565 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
566 | |
|
|
567 | if (pipe (respipe)) |
476 | if (s_epipe_renew (&respipe)) |
568 | croak ("unable to initialize result pipe"); |
477 | croak ("BDB: unable to create event pipe"); |
569 | |
|
|
570 | if (old_readfd >= 0) |
|
|
571 | { |
|
|
572 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
573 | croak ("unable to initialize result pipe(2)"); |
|
|
574 | |
|
|
575 | respipe_close (respipe [0]); |
|
|
576 | respipe [0] = old_readfd; |
|
|
577 | } |
|
|
578 | |
|
|
579 | #ifdef _WIN32 |
|
|
580 | arg = 1; |
|
|
581 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
582 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
583 | #else |
|
|
584 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
585 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
586 | #endif |
|
|
587 | croak ("unable to initialize result pipe(3)"); |
|
|
588 | |
|
|
589 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
590 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
591 | } |
478 | } |
592 | |
479 | |
593 | static void bdb_request (bdb_req req); |
480 | static void bdb_request (bdb_req req); |
594 | X_THREAD_PROC (bdb_proc); |
481 | X_THREAD_PROC (bdb_proc); |
595 | |
482 | |
… | |
… | |
599 | |
486 | |
600 | if (!wrk) |
487 | if (!wrk) |
601 | croak ("unable to allocate worker thread data"); |
488 | croak ("unable to allocate worker thread data"); |
602 | |
489 | |
603 | X_LOCK (wrklock); |
490 | X_LOCK (wrklock); |
604 | if (thread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
491 | if (xthread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
605 | { |
492 | { |
606 | wrk->prev = &wrk_first; |
493 | wrk->prev = &wrk_first; |
607 | wrk->next = wrk_first.next; |
494 | wrk->next = wrk_first.next; |
608 | wrk_first.next->prev = wrk; |
495 | wrk_first.next->prev = wrk; |
609 | wrk_first.next = wrk; |
496 | wrk_first.next = wrk; |
… | |
… | |
731 | end_thread (); |
618 | end_thread (); |
732 | } |
619 | } |
733 | |
620 | |
734 | static void poll_wait (void) |
621 | static void poll_wait (void) |
735 | { |
622 | { |
736 | fd_set rfd; |
|
|
737 | |
|
|
738 | while (nreqs) |
623 | while (nreqs) |
739 | { |
624 | { |
740 | int size; |
625 | int size; |
741 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
626 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
742 | size = res_queue.size; |
627 | size = res_queue.size; |
… | |
… | |
745 | if (size) |
630 | if (size) |
746 | return; |
631 | return; |
747 | |
632 | |
748 | maybe_start_thread (); |
633 | maybe_start_thread (); |
749 | |
634 | |
750 | FD_ZERO (&rfd); |
635 | s_epipe_wait (&respipe); |
751 | FD_SET (respipe [0], &rfd); |
|
|
752 | |
|
|
753 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
754 | } |
636 | } |
755 | } |
637 | } |
756 | |
638 | |
757 | static int poll_cb (void) |
639 | static int poll_cb (void) |
758 | { |
640 | { |
… | |
… | |
778 | if (req) |
660 | if (req) |
779 | { |
661 | { |
780 | --npending; |
662 | --npending; |
781 | |
663 | |
782 | if (!res_queue.size) |
664 | if (!res_queue.size) |
783 | { |
|
|
784 | /* read any signals sent by the worker threads */ |
665 | /* read any signals sent by the worker threads */ |
785 | char buf [4]; |
666 | s_epipe_drain (&respipe); |
786 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
787 | ; |
|
|
788 | } |
|
|
789 | } |
667 | } |
790 | |
668 | |
791 | X_UNLOCK (reslock); |
669 | X_UNLOCK (reslock); |
792 | |
670 | |
793 | if (!req) |
671 | if (!req) |
… | |
… | |
873 | |
751 | |
874 | case REQ_DB_CLOSE: |
752 | case REQ_DB_CLOSE: |
875 | req->result = req->db->close (req->db, req->uint1); |
753 | req->result = req->db->close (req->db, req->uint1); |
876 | break; |
754 | break; |
877 | |
755 | |
878 | #if DB_VERSION_MINOR >= 4 |
756 | #if DBVER >= 404 |
879 | case REQ_DB_COMPACT: |
757 | case REQ_DB_COMPACT: |
880 | req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0); |
758 | req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0); |
881 | break; |
759 | break; |
882 | #endif |
760 | #endif |
883 | |
761 | |
… | |
… | |
895 | |
773 | |
896 | case REQ_DB_PUT: |
774 | case REQ_DB_PUT: |
897 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
775 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
898 | break; |
776 | break; |
899 | |
777 | |
900 | #if DB_VERSION_MINOR >= 6 |
778 | #if DBVER >= 406 |
901 | case REQ_DB_EXISTS: |
779 | case REQ_DB_EXISTS: |
902 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
780 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
903 | break; |
781 | break; |
904 | #endif |
782 | #endif |
905 | case REQ_DB_GET: |
783 | case REQ_DB_GET: |
… | |
… | |
963 | |
841 | |
964 | case REQ_C_DEL: |
842 | case REQ_C_DEL: |
965 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
843 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
966 | break; |
844 | break; |
967 | |
845 | |
968 | #if DB_VERSION_MINOR >= 3 |
846 | #if DBVER >= 403 |
969 | case REQ_SEQ_OPEN: |
847 | case REQ_SEQ_OPEN: |
970 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
848 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
971 | break; |
849 | break; |
972 | |
850 | |
973 | case REQ_SEQ_CLOSE: |
851 | case REQ_SEQ_CLOSE: |
… | |
… | |
1009 | /* try to distribute timeouts somewhat evenly */ |
887 | /* try to distribute timeouts somewhat evenly */ |
1010 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
888 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1011 | |
889 | |
1012 | for (;;) |
890 | for (;;) |
1013 | { |
891 | { |
1014 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
892 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
1015 | |
893 | |
1016 | X_LOCK (reqlock); |
894 | X_LOCK (reqlock); |
1017 | |
895 | |
1018 | for (;;) |
896 | for (;;) |
1019 | { |
897 | { |
… | |
… | |
1064 | X_LOCK (reslock); |
942 | X_LOCK (reslock); |
1065 | |
943 | |
1066 | ++npending; |
944 | ++npending; |
1067 | |
945 | |
1068 | if (!reqq_push (&res_queue, req)) |
946 | if (!reqq_push (&res_queue, req)) |
1069 | /* write a dummy byte to the pipe so fh becomes ready */ |
947 | s_epipe_signal (&respipe); |
1070 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
1071 | |
948 | |
1072 | self->req = 0; |
949 | self->req = 0; |
1073 | worker_clear (self); |
950 | worker_clear (self); |
1074 | |
951 | |
1075 | X_UNLOCK (reslock); |
952 | X_UNLOCK (reslock); |
… | |
… | |
1151 | (void)0; |
1028 | (void)0; |
1152 | |
1029 | |
1153 | #define REQ_SEND \ |
1030 | #define REQ_SEND \ |
1154 | req_send (req) |
1031 | req_send (req) |
1155 | |
1032 | |
1156 | #define SvPTR(var, arg, type, class, nullok) \ |
1033 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1157 | if (!SvOK (arg)) \ |
1034 | if (!SvOK (arg)) \ |
1158 | { \ |
1035 | { \ |
1159 | if (nullok != 1) \ |
1036 | if (nullok != 1) \ |
1160 | croak (# var " must be a " # class " object, not undef"); \ |
1037 | croak (# var " must be a " # class " object, not undef"); \ |
1161 | \ |
1038 | \ |
1162 | (var) = 0; \ |
1039 | (var) = 0; \ |
1163 | } \ |
1040 | } \ |
1164 | else if (sv_derived_from ((arg), # class)) \ |
1041 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1165 | { \ |
1042 | { \ |
1166 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1043 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1167 | (var) = INT2PTR (type, tmp); \ |
1044 | (var) = INT2PTR (type, tmp); \ |
1168 | if (!var && nullok != 2) \ |
1045 | if (!var && nullok != 2) \ |
1169 | croak (# var " is not a valid " # class " object anymore"); \ |
1046 | croak (# var " is not a valid " # class " object anymore"); \ |
… | |
… | |
1172 | croak (# var " is not of type " # class); |
1049 | croak (# var " is not of type " # class); |
1173 | |
1050 | |
1174 | #define ARG_MUTABLE(name) \ |
1051 | #define ARG_MUTABLE(name) \ |
1175 | if (SvREADONLY (name)) \ |
1052 | if (SvREADONLY (name)) \ |
1176 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
1053 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
|
|
1054 | |
|
|
1055 | static SV * |
|
|
1056 | newSVptr (void *ptr, HV *stash) |
|
|
1057 | { |
|
|
1058 | SV *rv = NEWSV (0, 0); |
|
|
1059 | sv_upgrade (rv, SVt_PVMG); |
|
|
1060 | sv_setiv (rv, PTR2IV (ptr)); |
|
|
1061 | |
|
|
1062 | return sv_bless (newRV_noinc (rv), stash); |
|
|
1063 | } |
1177 | |
1064 | |
1178 | static void |
1065 | static void |
1179 | ptr_nuke (SV *sv) |
1066 | ptr_nuke (SV *sv) |
1180 | { |
1067 | { |
1181 | assert (SvROK (sv)); |
1068 | assert (SvROK (sv)); |
… | |
… | |
1303 | |
1190 | |
1304 | PROTOTYPES: ENABLE |
1191 | PROTOTYPES: ENABLE |
1305 | |
1192 | |
1306 | BOOT: |
1193 | BOOT: |
1307 | { |
1194 | { |
1308 | HV *stash = gv_stashpv ("BDB", 1); |
|
|
1309 | |
|
|
1310 | static const struct { |
1195 | static const struct { |
1311 | const char *name; |
1196 | const char *name; |
1312 | IV iv; |
1197 | IV iv; |
1313 | } *civ, const_iv[] = { |
1198 | } *civ, const_iv[] = { |
1314 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
1199 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
|
|
1200 | #if DBVER <= 408 |
1315 | const_iv (RPCCLIENT) |
1201 | const_iv (RPCCLIENT) |
|
|
1202 | #endif |
1316 | const_iv (INIT_CDB) |
1203 | const_iv (INIT_CDB) |
1317 | const_iv (INIT_LOCK) |
1204 | const_iv (INIT_LOCK) |
1318 | const_iv (INIT_LOG) |
1205 | const_iv (INIT_LOG) |
1319 | const_iv (INIT_MPOOL) |
1206 | const_iv (INIT_MPOOL) |
1320 | const_iv (INIT_REP) |
1207 | const_iv (INIT_REP) |
… | |
… | |
1343 | const_iv (TXN_NOT_DURABLE) |
1230 | const_iv (TXN_NOT_DURABLE) |
1344 | const_iv (TXN_WRITE_NOSYNC) |
1231 | const_iv (TXN_WRITE_NOSYNC) |
1345 | const_iv (WRITECURSOR) |
1232 | const_iv (WRITECURSOR) |
1346 | const_iv (YIELDCPU) |
1233 | const_iv (YIELDCPU) |
1347 | const_iv (ENCRYPT_AES) |
1234 | const_iv (ENCRYPT_AES) |
|
|
1235 | #if DBVER < 408 |
1348 | const_iv (XA_CREATE) |
1236 | const_iv (XA_CREATE) |
|
|
1237 | #endif |
1349 | const_iv (BTREE) |
1238 | const_iv (BTREE) |
1350 | const_iv (HASH) |
1239 | const_iv (HASH) |
1351 | const_iv (QUEUE) |
1240 | const_iv (QUEUE) |
1352 | const_iv (RECNO) |
1241 | const_iv (RECNO) |
1353 | const_iv (UNKNOWN) |
1242 | const_iv (UNKNOWN) |
… | |
… | |
1417 | const_iv (LOCK_OLDEST) |
1306 | const_iv (LOCK_OLDEST) |
1418 | const_iv (LOCK_RANDOM) |
1307 | const_iv (LOCK_RANDOM) |
1419 | const_iv (LOCK_YOUNGEST) |
1308 | const_iv (LOCK_YOUNGEST) |
1420 | |
1309 | |
1421 | const_iv (DONOTINDEX) |
1310 | const_iv (DONOTINDEX) |
1422 | const_iv (KEYEMPTY ) |
1311 | const_iv (KEYEMPTY) |
1423 | const_iv (KEYEXIST ) |
1312 | const_iv (KEYEXIST) |
1424 | const_iv (LOCK_DEADLOCK) |
1313 | const_iv (LOCK_DEADLOCK) |
1425 | const_iv (LOCK_NOTGRANTED) |
1314 | const_iv (LOCK_NOTGRANTED) |
1426 | const_iv (NOSERVER) |
1315 | const_iv (NOSERVER) |
|
|
1316 | #if DBVER < 502 |
1427 | const_iv (NOSERVER_HOME) |
1317 | const_iv (NOSERVER_HOME) |
1428 | const_iv (NOSERVER_ID) |
1318 | const_iv (NOSERVER_ID) |
|
|
1319 | #endif |
1429 | const_iv (NOTFOUND) |
1320 | const_iv (NOTFOUND) |
1430 | const_iv (PAGE_NOTFOUND) |
1321 | const_iv (PAGE_NOTFOUND) |
1431 | const_iv (REP_DUPMASTER) |
1322 | const_iv (REP_DUPMASTER) |
1432 | const_iv (REP_HANDLE_DEAD) |
1323 | const_iv (REP_HANDLE_DEAD) |
1433 | const_iv (REP_HOLDELECTION) |
1324 | const_iv (REP_HOLDELECTION) |
… | |
… | |
1457 | const_iv (VERB_WAITSFOR) |
1348 | const_iv (VERB_WAITSFOR) |
1458 | |
1349 | |
1459 | const_iv (VERSION_MAJOR) |
1350 | const_iv (VERSION_MAJOR) |
1460 | const_iv (VERSION_MINOR) |
1351 | const_iv (VERSION_MINOR) |
1461 | const_iv (VERSION_PATCH) |
1352 | const_iv (VERSION_PATCH) |
1462 | #if DB_VERSION_MINOR >= 3 |
1353 | const_iv (LOGVERSION) |
|
|
1354 | const_iv (LOGOLDVER) |
|
|
1355 | #if DBVER >= 403 |
1463 | const_iv (INORDER) |
1356 | const_iv (INORDER) |
1464 | const_iv (LOCK_MAXWRITE) |
1357 | const_iv (LOCK_MAXWRITE) |
1465 | const_iv (SEQ_DEC) |
1358 | const_iv (SEQ_DEC) |
1466 | const_iv (SEQ_INC) |
1359 | const_iv (SEQ_INC) |
1467 | const_iv (SEQ_WRAP) |
1360 | const_iv (SEQ_WRAP) |
1468 | const_iv (BUFFER_SMALL) |
1361 | const_iv (BUFFER_SMALL) |
1469 | const_iv (LOG_BUFFER_FULL) |
1362 | const_iv (LOG_BUFFER_FULL) |
1470 | const_iv (VERSION_MISMATCH) |
1363 | const_iv (VERSION_MISMATCH) |
1471 | #endif |
1364 | #endif |
1472 | #if DB_VERSION_MINOR >= 4 |
1365 | #if DBVER >= 404 |
1473 | const_iv (REGISTER) |
1366 | const_iv (REGISTER) |
1474 | const_iv (DSYNC_DB) |
1367 | const_iv (DSYNC_DB) |
1475 | const_iv (READ_COMMITTED) |
1368 | const_iv (READ_COMMITTED) |
1476 | const_iv (READ_UNCOMMITTED) |
1369 | const_iv (READ_UNCOMMITTED) |
1477 | const_iv (REP_IGNORE) |
1370 | const_iv (REP_IGNORE) |
… | |
… | |
1479 | const_iv (REP_JOIN_FAILURE) |
1372 | const_iv (REP_JOIN_FAILURE) |
1480 | const_iv (FREE_SPACE) |
1373 | const_iv (FREE_SPACE) |
1481 | const_iv (FREELIST_ONLY) |
1374 | const_iv (FREELIST_ONLY) |
1482 | const_iv (VERB_REGISTER) |
1375 | const_iv (VERB_REGISTER) |
1483 | #endif |
1376 | #endif |
1484 | #if DB_VERSION_MINOR >= 5 |
1377 | #if DBVER >= 405 |
1485 | const_iv (MULTIVERSION) |
1378 | const_iv (MULTIVERSION) |
1486 | const_iv (TXN_SNAPSHOT) |
1379 | const_iv (TXN_SNAPSHOT) |
1487 | #endif |
1380 | #endif |
1488 | #if DB_VERSION_MINOR >= 6 |
1381 | #if DBVER >= 406 |
1489 | const_iv (PREV_DUP) |
1382 | const_iv (PREV_DUP) |
1490 | const_iv (PRIORITY_UNCHANGED) |
1383 | const_iv (PRIORITY_UNCHANGED) |
1491 | const_iv (PRIORITY_VERY_LOW) |
1384 | const_iv (PRIORITY_VERY_LOW) |
1492 | const_iv (PRIORITY_LOW) |
1385 | const_iv (PRIORITY_LOW) |
1493 | const_iv (PRIORITY_DEFAULT) |
1386 | const_iv (PRIORITY_DEFAULT) |
1494 | const_iv (PRIORITY_HIGH) |
1387 | const_iv (PRIORITY_HIGH) |
1495 | const_iv (PRIORITY_VERY_HIGH) |
1388 | const_iv (PRIORITY_VERY_HIGH) |
1496 | const_iv (IGNORE_LEASE) |
1389 | const_iv (IGNORE_LEASE) |
1497 | #endif |
1390 | #endif |
1498 | #if DB_VERSION_MINOR >= 7 |
1391 | #if DBVER >= 407 |
1499 | //const_iv (MULTIPLE_KEY) |
1392 | //const_iv (MULTIPLE_KEY) |
1500 | const_iv (LOG_DIRECT) |
1393 | const_iv (LOG_DIRECT) |
1501 | const_iv (LOG_DSYNC) |
1394 | const_iv (LOG_DSYNC) |
1502 | const_iv (LOG_AUTO_REMOVE) |
1395 | const_iv (LOG_AUTO_REMOVE) |
1503 | const_iv (LOG_IN_MEMORY) |
1396 | const_iv (LOG_IN_MEMORY) |
1504 | const_iv (LOG_ZERO) |
1397 | const_iv (LOG_ZERO) |
1505 | #else |
1398 | #else |
1506 | const_iv (DIRECT_LOG) |
1399 | const_iv (DIRECT_LOG) |
1507 | const_iv (LOG_AUTOREMOVE) |
1400 | const_iv (LOG_AUTOREMOVE) |
1508 | # if DB_VERSION_MINOR >= 3 |
1401 | # if DBVER >= 403 |
1509 | const_iv (DSYNC_LOG) |
1402 | const_iv (DSYNC_LOG) |
1510 | const_iv (LOG_INMEMORY) |
1403 | const_iv (LOG_INMEMORY) |
1511 | # endif |
1404 | # endif |
|
|
1405 | #if DBVER >= 408 |
|
|
1406 | const_iv (LOGVERSION_LATCHING) |
|
|
1407 | #endif |
1512 | #endif |
1408 | #endif |
1513 | }; |
1409 | }; |
1514 | |
1410 | |
|
|
1411 | bdb_stash = gv_stashpv ("BDB" , 1); |
|
|
1412 | bdb_env_stash = gv_stashpv ("BDB::Env" , 1); |
|
|
1413 | bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1); |
|
|
1414 | bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1); |
|
|
1415 | bdb_db_stash = gv_stashpv ("BDB::Db" , 1); |
|
|
1416 | bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1); |
|
|
1417 | |
1515 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1418 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
1516 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1419 | newCONSTSUB (bdb_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
1517 | |
1420 | |
1518 | prepare_cb = &PL_sv_undef; |
1421 | prepare_cb = &PL_sv_undef; |
1519 | |
1422 | |
1520 | { |
1423 | { |
1521 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1424 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1522 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1425 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1523 | |
1426 | |
1524 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1427 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1525 | } |
1428 | } |
1526 | |
1429 | |
1527 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1430 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1528 | |
1431 | |
1529 | create_respipe (); |
1432 | create_respipe (); |
1530 | |
1433 | |
1531 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1434 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1532 | patch_errno (); |
1435 | patch_errno (); |
… | |
… | |
1610 | |
1513 | |
1611 | int |
1514 | int |
1612 | poll_fileno () |
1515 | poll_fileno () |
1613 | PROTOTYPE: |
1516 | PROTOTYPE: |
1614 | CODE: |
1517 | CODE: |
1615 | RETVAL = respipe [0]; |
1518 | RETVAL = s_epipe_fd (&respipe); |
1616 | OUTPUT: |
1519 | OUTPUT: |
1617 | RETVAL |
1520 | RETVAL |
1618 | |
1521 | |
1619 | int |
1522 | int |
1620 | poll_cb (...) |
1523 | poll_cb (...) |
… | |
… | |
1866 | req->uint1 = flags; |
1769 | req->uint1 = flags; |
1867 | req->sv1 = (SV *)db->app_private; |
1770 | req->sv1 = (SV *)db->app_private; |
1868 | REQ_SEND; |
1771 | REQ_SEND; |
1869 | } |
1772 | } |
1870 | |
1773 | |
1871 | #if DB_VERSION_MINOR >= 4 |
1774 | #if DBVER >= 404 |
1872 | |
1775 | |
1873 | void |
1776 | void |
1874 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1777 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1875 | PREINIT: |
1778 | PREINIT: |
1876 | CALLBACK |
1779 | CALLBACK |
… | |
… | |
1955 | sv_to_dbt (&req->dbt2, data); |
1858 | sv_to_dbt (&req->dbt2, data); |
1956 | req->uint1 = flags; |
1859 | req->uint1 = flags; |
1957 | REQ_SEND; |
1860 | REQ_SEND; |
1958 | } |
1861 | } |
1959 | |
1862 | |
1960 | #if DB_VERSION_MINOR >= 6 |
1863 | #if DBVER >= 406 |
1961 | |
1864 | |
1962 | void |
1865 | void |
1963 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1866 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1964 | PREINIT: |
1867 | PREINIT: |
1965 | CALLBACK |
1868 | CALLBACK |
… | |
… | |
2198 | req->uint1 = flags; |
2101 | req->uint1 = flags; |
2199 | REQ_SEND; |
2102 | REQ_SEND; |
2200 | } |
2103 | } |
2201 | |
2104 | |
2202 | |
2105 | |
2203 | #if DB_VERSION_MINOR >= 3 |
2106 | #if DBVER >= 403 |
2204 | |
2107 | |
2205 | void |
2108 | void |
2206 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2109 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2207 | PREINIT: |
2110 | PREINIT: |
2208 | CALLBACK |
2111 | CALLBACK |
… | |
… | |
2302 | CODE: |
2205 | CODE: |
2303 | RETVAL = env->set_flags (env, flags, onoff); |
2206 | RETVAL = env->set_flags (env, flags, onoff); |
2304 | OUTPUT: |
2207 | OUTPUT: |
2305 | RETVAL |
2208 | RETVAL |
2306 | |
2209 | |
2307 | #if DB_VERSION_MINOR >= 7 |
2210 | #if DBVER >= 407 |
2308 | |
2211 | |
2309 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2212 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2310 | CODE: |
2213 | CODE: |
2311 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2214 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2312 | OUTPUT: |
2215 | OUTPUT: |
… | |
… | |
2399 | CODE: |
2302 | CODE: |
2400 | RETVAL = env->set_lg_max (env, max); |
2303 | RETVAL = env->set_lg_max (env, max); |
2401 | OUTPUT: |
2304 | OUTPUT: |
2402 | RETVAL |
2305 | RETVAL |
2403 | |
2306 | |
2404 | #if DB_VERSION_MINOR >= 4 |
2307 | #if DBVER >= 404 |
2405 | |
2308 | |
2406 | int mutex_set_max (DB_ENV *env, U32 max) |
2309 | int mutex_set_max (DB_ENV *env, U32 max) |
2407 | CODE: |
2310 | CODE: |
2408 | RETVAL = env->mutex_set_max (env, max); |
2311 | RETVAL = env->mutex_set_max (env, max); |
2409 | OUTPUT: |
2312 | OUTPUT: |
… | |
… | |
2436 | if (errno) |
2339 | if (errno) |
2437 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2340 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2438 | OUTPUT: |
2341 | OUTPUT: |
2439 | RETVAL |
2342 | RETVAL |
2440 | |
2343 | |
2441 | #if DB_VERSION_MINOR >= 5 |
2344 | #if DBVER >= 405 |
2442 | |
2345 | |
2443 | DB_TXN * |
2346 | DB_TXN * |
2444 | cdsgroup_begin (DB_ENV *env) |
2347 | cdsgroup_begin (DB_ENV *env) |
2445 | CODE: |
2348 | CODE: |
2446 | errno = env->cdsgroup_begin (env, &RETVAL); |
2349 | errno = env->cdsgroup_begin (env, &RETVAL); |
… | |
… | |
2548 | if (errno) |
2451 | if (errno) |
2549 | croak ("DB->cursor: %s", db_strerror (errno)); |
2452 | croak ("DB->cursor: %s", db_strerror (errno)); |
2550 | OUTPUT: |
2453 | OUTPUT: |
2551 | RETVAL |
2454 | RETVAL |
2552 | |
2455 | |
2553 | #if DB_VERSION_MINOR >= 3 |
2456 | #if DBVER >= 403 |
2554 | |
2457 | |
2555 | DB_SEQUENCE * |
2458 | DB_SEQUENCE * |
2556 | sequence (DB *db, U32 flags = 0) |
2459 | sequence (DB *db, U32 flags = 0) |
2557 | CODE: |
2460 | CODE: |
2558 | { |
2461 | { |
… | |
… | |
2593 | DESTROY (DBC_ornuked *dbc) |
2496 | DESTROY (DBC_ornuked *dbc) |
2594 | CODE: |
2497 | CODE: |
2595 | if (dbc) |
2498 | if (dbc) |
2596 | dbc->c_close (dbc); |
2499 | dbc->c_close (dbc); |
2597 | |
2500 | |
2598 | #if DB_VERSION_MINOR >= 6 |
2501 | #if DBVER >= 406 |
2599 | |
2502 | |
2600 | int set_priority (DBC *dbc, int priority) |
2503 | int set_priority (DBC *dbc, int priority) |
2601 | CODE: |
2504 | CODE: |
2602 | dbc->set_priority (dbc, priority); |
2505 | dbc->set_priority (dbc, priority); |
2603 | |
2506 | |
2604 | #endif |
2507 | #endif |
2605 | |
2508 | |
2606 | #if DB_VERSION_MINOR >= 3 |
2509 | #if DBVER >= 403 |
2607 | |
2510 | |
2608 | MODULE = BDB PACKAGE = BDB::Sequence |
2511 | MODULE = BDB PACKAGE = BDB::Sequence |
2609 | |
2512 | |
2610 | void |
2513 | void |
2611 | DESTROY (DB_SEQUENCE_ornuked *seq) |
2514 | DESTROY (DB_SEQUENCE_ornuked *seq) |