… | |
… | |
64 | #endif |
64 | #endif |
65 | |
65 | |
66 | static char * |
66 | static char * |
67 | get_bdb_filename (SV *sv) |
67 | get_bdb_filename (SV *sv) |
68 | { |
68 | { |
69 | return !SvOK (sv) |
69 | if (!SvOK (sv)) |
70 | ? 0 |
70 | return 0; |
71 | : |
71 | |
72 | #if WIN32 |
72 | #if _WIN32 |
73 | SvPVutf8_nolen (sv) |
73 | /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */ |
|
|
74 | { |
|
|
75 | STRLEN len; |
|
|
76 | char *src = SvPVbyte (sv, len); |
|
|
77 | SV *t1 = sv_newmortal (); |
|
|
78 | SV *t2 = sv_newmortal (); |
|
|
79 | |
|
|
80 | sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1); |
|
|
81 | sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1); |
|
|
82 | |
|
|
83 | len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR)); |
|
|
84 | len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0); |
|
|
85 | SvPOK_only (t2); |
|
|
86 | SvPVX (t2)[len] = 0; |
|
|
87 | SvCUR_set (t2, len); |
|
|
88 | |
|
|
89 | return SvPVX (t2); |
|
|
90 | } |
74 | #else |
91 | #else |
75 | SvPVbyte_nolen (sv) |
92 | return SvPVbyte_nolen (sv); |
76 | #endif |
93 | #endif |
77 | ; |
|
|
78 | } |
94 | } |
79 | |
95 | |
80 | static void |
96 | static void |
81 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
97 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
82 | { |
98 | { |
… | |
… | |
121 | } |
137 | } |
122 | |
138 | |
123 | enum { |
139 | enum { |
124 | REQ_QUIT, |
140 | REQ_QUIT, |
125 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
141 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
126 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
142 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
127 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
143 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
128 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
144 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
129 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
145 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
130 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
146 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
131 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
147 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
… | |
… | |
143 | DBC *dbc; |
159 | DBC *dbc; |
144 | |
160 | |
145 | UV uv1; |
161 | UV uv1; |
146 | int int1, int2; |
162 | int int1, int2; |
147 | U32 uint1, uint2; |
163 | U32 uint1, uint2; |
148 | char *buf1, *buf2; |
164 | char *buf1, *buf2, *buf3; |
149 | SV *sv1, *sv2, *sv3; |
165 | SV *sv1, *sv2, *sv3; |
150 | |
166 | |
151 | DBT dbt1, dbt2, dbt3; |
167 | DBT dbt1, dbt2, dbt3; |
152 | DB_KEY_RANGE key_range; |
168 | DB_KEY_RANGE key_range; |
153 | DB_SEQUENCE *seq; |
169 | DB_SEQUENCE *seq; |
… | |
… | |
164 | PRI_BIAS = -PRI_MIN, |
180 | PRI_BIAS = -PRI_MIN, |
165 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
181 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
166 | }; |
182 | }; |
167 | |
183 | |
168 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
184 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
|
|
185 | |
|
|
186 | static SV *on_next_submit; |
169 | |
187 | |
170 | static unsigned int max_poll_time = 0; |
188 | static unsigned int max_poll_time = 0; |
171 | static unsigned int max_poll_reqs = 0; |
189 | static unsigned int max_poll_reqs = 0; |
172 | |
190 | |
173 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
191 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
… | |
… | |
395 | |
413 | |
396 | static void req_free (bdb_req req) |
414 | static void req_free (bdb_req req) |
397 | { |
415 | { |
398 | free (req->buf1); |
416 | free (req->buf1); |
399 | free (req->buf2); |
417 | free (req->buf2); |
|
|
418 | free (req->buf3); |
400 | Safefree (req); |
419 | Safefree (req); |
401 | } |
420 | } |
402 | |
421 | |
403 | #ifdef USE_SOCKETS_AS_HANDLES |
422 | #ifdef USE_SOCKETS_AS_HANDLES |
404 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
423 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
… | |
… | |
484 | } |
503 | } |
485 | |
504 | |
486 | static void req_send (bdb_req req) |
505 | static void req_send (bdb_req req) |
487 | { |
506 | { |
488 | SV *wait_callback = 0; |
507 | SV *wait_callback = 0; |
|
|
508 | |
|
|
509 | if (on_next_submit) |
|
|
510 | { |
|
|
511 | dSP; |
|
|
512 | SV *cb = sv_2mortal (on_next_submit); |
|
|
513 | |
|
|
514 | on_next_submit = 0; |
|
|
515 | |
|
|
516 | PUSHMARK (SP); |
|
|
517 | PUTBACK; |
|
|
518 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
519 | } |
489 | |
520 | |
490 | // synthesize callback if none given |
521 | // synthesize callback if none given |
491 | if (!SvOK (req->callback)) |
522 | if (!SvOK (req->callback)) |
492 | { |
523 | { |
493 | int count; |
524 | int count; |
… | |
… | |
740 | req->result = req->env->memp_sync (req->env, 0); |
771 | req->result = req->env->memp_sync (req->env, 0); |
741 | break; |
772 | break; |
742 | |
773 | |
743 | case REQ_ENV_MEMP_TRICKLE: |
774 | case REQ_ENV_MEMP_TRICKLE: |
744 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
775 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
|
|
776 | break; |
|
|
777 | |
|
|
778 | case REQ_ENV_DBREMOVE: |
|
|
779 | req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1); |
|
|
780 | break; |
|
|
781 | |
|
|
782 | case REQ_ENV_DBRENAME: |
|
|
783 | req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1); |
745 | break; |
784 | break; |
746 | |
785 | |
747 | case REQ_DB_OPEN: |
786 | case REQ_DB_OPEN: |
748 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
787 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
749 | break; |
788 | break; |
… | |
… | |
1041 | const_iv (REGISTER) |
1080 | const_iv (REGISTER) |
1042 | const_iv (SYSTEM_MEM) |
1081 | const_iv (SYSTEM_MEM) |
1043 | const_iv (AUTO_COMMIT) |
1082 | const_iv (AUTO_COMMIT) |
1044 | const_iv (CDB_ALLDB) |
1083 | const_iv (CDB_ALLDB) |
1045 | const_iv (DIRECT_DB) |
1084 | const_iv (DIRECT_DB) |
1046 | const_iv (DIRECT_LOG) |
|
|
1047 | const_iv (DSYNC_DB) |
1085 | const_iv (DSYNC_DB) |
1048 | const_iv (DSYNC_LOG) |
|
|
1049 | const_iv (LOG_AUTOREMOVE) |
|
|
1050 | const_iv (LOG_INMEMORY) |
|
|
1051 | const_iv (NOLOCKING) |
1086 | const_iv (NOLOCKING) |
1052 | const_iv (NOMMAP) |
1087 | const_iv (NOMMAP) |
1053 | const_iv (NOPANIC) |
1088 | const_iv (NOPANIC) |
1054 | const_iv (OVERWRITE) |
1089 | const_iv (OVERWRITE) |
1055 | const_iv (PANIC_ENVIRONMENT) |
1090 | const_iv (PANIC_ENVIRONMENT) |
… | |
… | |
1194 | const_iv (PRIORITY_LOW) |
1229 | const_iv (PRIORITY_LOW) |
1195 | const_iv (PRIORITY_DEFAULT) |
1230 | const_iv (PRIORITY_DEFAULT) |
1196 | const_iv (PRIORITY_HIGH) |
1231 | const_iv (PRIORITY_HIGH) |
1197 | const_iv (PRIORITY_VERY_HIGH) |
1232 | const_iv (PRIORITY_VERY_HIGH) |
1198 | #endif |
1233 | #endif |
|
|
1234 | #if DB_VERSION_MINOR >= 7 |
|
|
1235 | const_iv (LOG_DIRECT) |
|
|
1236 | const_iv (LOG_DSYNC) |
|
|
1237 | const_iv (LOG_AUTO_REMOVE) |
|
|
1238 | const_iv (LOG_IN_MEMORY) |
|
|
1239 | const_iv (LOG_ZERO) |
|
|
1240 | #else |
|
|
1241 | const_iv (DIRECT_LOG) |
|
|
1242 | const_iv (DSYNC_LOG) |
|
|
1243 | const_iv (LOG_AUTOREMOVE) |
|
|
1244 | const_iv (LOG_INMEMORY) |
|
|
1245 | #endif |
1199 | }; |
1246 | }; |
1200 | |
1247 | |
1201 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1248 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1202 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1249 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1203 | |
1250 | |
… | |
… | |
1205 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1252 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1206 | |
1253 | |
1207 | create_respipe (); |
1254 | create_respipe (); |
1208 | |
1255 | |
1209 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1256 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1210 | #ifdef _WIN32 |
|
|
1211 | X_MUTEX_CHECK (wrklock); |
|
|
1212 | X_MUTEX_CHECK (reslock); |
|
|
1213 | X_MUTEX_CHECK (reqlock); |
|
|
1214 | |
|
|
1215 | X_COND_CHECK (reqwait); |
|
|
1216 | #endif |
|
|
1217 | patch_errno (); |
1257 | patch_errno (); |
1218 | } |
1258 | } |
1219 | |
1259 | |
1220 | void |
1260 | void |
1221 | max_poll_reqs (int nreqs) |
1261 | max_poll_reqs (int nreqs) |
… | |
… | |
1362 | CODE: |
1402 | CODE: |
1363 | RETVAL = db_strerror (errorno); |
1403 | RETVAL = db_strerror (errorno); |
1364 | OUTPUT: |
1404 | OUTPUT: |
1365 | RETVAL |
1405 | RETVAL |
1366 | |
1406 | |
|
|
1407 | void _on_next_submit (SV *cb) |
|
|
1408 | CODE: |
|
|
1409 | SvREFCNT_dec (on_next_submit); |
|
|
1410 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1411 | |
1367 | DB_ENV * |
1412 | DB_ENV * |
1368 | db_env_create (U32 env_flags = 0) |
1413 | db_env_create (U32 env_flags = 0) |
1369 | CODE: |
1414 | CODE: |
1370 | { |
1415 | { |
1371 | errno = db_env_create (&RETVAL, env_flags); |
1416 | errno = db_env_create (&RETVAL, env_flags); |
… | |
… | |
1445 | req->env = env; |
1490 | req->env = env; |
1446 | req->int1 = percent; |
1491 | req->int1 = percent; |
1447 | REQ_SEND; |
1492 | REQ_SEND; |
1448 | } |
1493 | } |
1449 | |
1494 | |
|
|
1495 | void |
|
|
1496 | db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1497 | CODE: |
|
|
1498 | { |
|
|
1499 | dREQ (REQ_ENV_DBREMOVE); |
|
|
1500 | req->env = env; |
|
|
1501 | req->buf1 = strdup_ornull (file); |
|
|
1502 | req->buf2 = strdup_ornull (database); |
|
|
1503 | req->uint1 = flags; |
|
|
1504 | REQ_SEND; |
|
|
1505 | } |
|
|
1506 | |
|
|
1507 | void |
|
|
1508 | db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1509 | CODE: |
|
|
1510 | { |
|
|
1511 | dREQ (REQ_ENV_DBRENAME); |
|
|
1512 | req->env = env; |
|
|
1513 | req->buf1 = strdup_ornull (file); |
|
|
1514 | req->buf2 = strdup_ornull (database); |
|
|
1515 | req->buf3 = strdup_ornull (newname); |
|
|
1516 | req->uint1 = flags; |
|
|
1517 | REQ_SEND; |
|
|
1518 | } |
1450 | |
1519 | |
1451 | DB * |
1520 | DB * |
1452 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1521 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1453 | CODE: |
1522 | CODE: |
1454 | { |
1523 | { |
… | |
… | |
1812 | CODE: |
1881 | CODE: |
1813 | RETVAL = env->set_flags (env, flags, onoff); |
1882 | RETVAL = env->set_flags (env, flags, onoff); |
1814 | OUTPUT: |
1883 | OUTPUT: |
1815 | RETVAL |
1884 | RETVAL |
1816 | |
1885 | |
|
|
1886 | #if DB_VERSION_MINOR >= 7 |
|
|
1887 | |
|
|
1888 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
|
|
1889 | CODE: |
|
|
1890 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
|
|
1891 | OUTPUT: |
|
|
1892 | RETVAL |
|
|
1893 | |
|
|
1894 | int log_set_config (DB_ENV *env, U32 flags, int onoff = 1) |
|
|
1895 | CODE: |
|
|
1896 | RETVAL = env->log_set_config (env, flags, onoff); |
|
|
1897 | OUTPUT: |
|
|
1898 | RETVAL |
|
|
1899 | |
|
|
1900 | #endif |
|
|
1901 | |
|
|
1902 | |
1817 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1903 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1818 | CODE: |
1904 | CODE: |
1819 | env->set_errfile (env, errfile); |
1905 | env->set_errfile (env, errfile); |
1820 | |
1906 | |
1821 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
1907 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |