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

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.223 by root, Tue Aug 28 03:13:33 2012 UTC vs.
Revision 1.233 by root, Thu Jun 25 13:34:28 2015 UTC

19 19
20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
21# include <sys/mman.h> 21# include <sys/mman.h>
22#endif 22#endif
23 23
24#if __linux__ 24/* the incompetent fool that created musl keeps __linux__, refuses
25 * to implement any linux standard apis, and also has no way to test
26 * for his broken iplementation. on't complain if this fails for you.
27 */
28#if __linux__ && (defined __GLIBC__ || defined __UCLIBC__)
25# include <linux/fs.h> 29# include <linux/fs.h>
26# ifdef FS_IOC_FIEMAP 30# ifdef FS_IOC_FIEMAP
27# include <linux/types.h> 31# include <linux/types.h>
28# include <linux/fiemap.h> 32# include <linux/fiemap.h>
29# define HAVE_FIEMAP 1 33# define HAVE_FIEMAP 1
153#endif 157#endif
154#ifndef minor 158#ifndef minor
155# define minor(dev) ((dev) & 0xff) 159# define minor(dev) ((dev) & 0xff)
156#endif 160#endif
157 161
158#ifndef PAGESIZE 162#if PAGESIZE <= 0
159# define PAGESIZE sysconf (_SC_PAGESIZE) 163# define PAGESIZE sysconf (_SC_PAGESIZE)
160#endif 164#endif
161 165
162/*****************************************************************************/ 166/*****************************************************************************/
163 167
198 || !fiemap->fm_mapped_extents /* no more extents */ 202 || !fiemap->fm_mapped_extents /* no more extents */
199 || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) 203 || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */)
200 goto done; 204 goto done;
201 205
202 /* else we have to loop - 206 /* else we have to loop -
203 * it would be tempting (atcually I tried that first) to just query the 207 * it would be tempting (actually I tried that first) to just query the
204 * number of extents needed, but linux often feels like not returning all 208 * number of extents needed, but linux often feels like not returning all
205 * extents, without telling us it left any out. this complicates 209 * extents, without telling us it left any out. this complicates
206 * this quite a bit. 210 * this quite a bit.
207 */ 211 */
208 212
221 incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); 225 incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent);
222 226
223 if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) 227 if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0)
224 return; 228 return;
225 229
230 if (!incmap->fm_mapped_extents)
231 goto done;
232
226 count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; 233 count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents;
227 fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); 234 fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
228 errno = ENOMEM; 235 errno = ENOMEM;
229 if (!fiemap) 236 if (!fiemap)
230 return; 237 return;
301} 308}
302 309
303static SV * 310static SV *
304newSVaio_wd (aio_wd wd) 311newSVaio_wd (aio_wd wd)
305{ 312{
306 return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); 313 return sv_bless (newRV_noinc (newSViv ((intptr_t)wd)), aio_wd_stash);
307} 314}
308 315
309static aio_req 316static aio_req
310SvAIO_REQ (SV *sv) 317SvAIO_REQ (SV *sv)
311{ 318{
330 || SvTYPE (SvRV (sv)) != SVt_PVMG 337 || SvTYPE (SvRV (sv)) != SVt_PVMG
331 || SvSTASH (SvRV (sv)) != aio_wd_stash) 338 || SvSTASH (SvRV (sv)) != aio_wd_stash)
332 croak ("IO::AIO: expected a working directory object as returned by aio_wd"); 339 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
333 340
334 return (aio_wd)(long)SvIVX (SvRV (sv)); 341 return (aio_wd)(long)SvIVX (SvRV (sv));
342}
343
344static SV *
345newmortalFH (int fd, int flags)
346{
347 if (fd < 0)
348 return &PL_sv_undef;
349
350 GV *gv = (GV *)sv_newmortal ();
351 char sym[64];
352 int symlen;
353
354 symlen = snprintf (sym, sizeof (sym), "fd#%d", fd);
355 gv_init (gv, aio_stash, sym, symlen, 0);
356
357 symlen = snprintf (
358 sym,
359 sizeof (sym),
360 "%s&=%d",
361 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
362 fd
363 );
364
365 return do_open (gv, sym, symlen, 0, 0, 0, 0)
366 ? (SV *)gv : &PL_sv_undef;
335} 367}
336 368
337static void 369static void
338aio_grp_feed (aio_req grp) 370aio_grp_feed (aio_req grp)
339{ 371{
467 XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); 499 XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2))));
468 } 500 }
469 break; 501 break;
470 502
471 case EIO_OPEN: 503 case EIO_OPEN:
472 { 504 PUSHs (newmortalFH (req->result, req->int1 & (O_RDONLY | O_WRONLY | O_RDWR)));
473 /* convert fd to fh */
474 SV *fh = &PL_sv_undef;
475
476 if (req->result >= 0)
477 {
478 GV *gv = (GV *)sv_newmortal ();
479 int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR);
480 char sym [64];
481 int symlen;
482
483 symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result);
484 gv_init (gv, aio_stash, sym, symlen, 0);
485
486 symlen = snprintf (
487 sym,
488 sizeof (sym),
489 "%s&=%d",
490 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
491 (int)req->result
492 );
493
494 if (do_open (gv, sym, symlen, 0, 0, 0, 0))
495 fh = (SV *)gv;
496 }
497
498 PUSHs (fh);
499 }
500 break; 505 break;
501 506
502 case EIO_STATVFS: 507 case EIO_STATVFS:
503 case EIO_FSTATVFS: 508 case EIO_FSTATVFS:
504 { 509 {
507#ifndef _WIN32 512#ifndef _WIN32
508 if (req->result >= 0) 513 if (req->result >= 0)
509 { 514 {
510 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 515 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
511 HV *hv = newHV (); 516 HV *hv = newHV ();
517 /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom
518 * chooses to make it a struct.
519 */
520 unsigned long fsid = 0;
521 memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid));
512 522
513 rv = sv_2mortal (newRV_noinc ((SV *)hv)); 523 rv = sv_2mortal (newRV_noinc ((SV *)hv));
514 524
515 hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); 525 hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0);
516 hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); 526 hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0);
518 hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); 528 hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0);
519 hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); 529 hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0);
520 hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); 530 hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0);
521 hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); 531 hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0);
522 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 532 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0);
523 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); 533 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0);
524 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); 534 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0);
525 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); 535 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
526 } 536 }
527#endif 537#endif
528 538
1021 const_eio (SYNC_FILE_RANGE_WRITE) 1031 const_eio (SYNC_FILE_RANGE_WRITE)
1022 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 1032 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
1023 1033
1024 const_eio (FALLOC_FL_KEEP_SIZE) 1034 const_eio (FALLOC_FL_KEEP_SIZE)
1025 const_eio (FALLOC_FL_PUNCH_HOLE) 1035 const_eio (FALLOC_FL_PUNCH_HOLE)
1036 const_eio (FALLOC_FL_COLLAPSE_RANGE)
1037 const_eio (FALLOC_FL_ZERO_RANGE)
1026 1038
1027 const_eio (READDIR_DENTS) 1039 const_eio (READDIR_DENTS)
1028 const_eio (READDIR_DIRS_FIRST) 1040 const_eio (READDIR_DIRS_FIRST)
1029 const_eio (READDIR_STAT_ORDER) 1041 const_eio (READDIR_STAT_ORDER)
1030 const_eio (READDIR_FOUND_UNKNOWN) 1042 const_eio (READDIR_FOUND_UNKNOWN)
1098 PROTOTYPE: $ 1110 PROTOTYPE: $
1099 CODE: 1111 CODE:
1100 max_outstanding = maxreqs; 1112 max_outstanding = maxreqs;
1101 1113
1102void 1114void
1103aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) 1115aio_wd (SV8 *pathname, SV *callback = &PL_sv_undef)
1104 PPCODE: 1116 PPCODE:
1105{ 1117{
1106 dREQ; 1118 dREQ;
1107 1119
1108 req->type = EIO_WD_OPEN; 1120 req->type = EIO_WD_OPEN;
1110 1122
1111 REQ_SEND; 1123 REQ_SEND;
1112} 1124}
1113 1125
1114void 1126void
1115aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1127aio_open (SV8 *pathname, int flags, int mode, SV *callback = &PL_sv_undef)
1116 PPCODE: 1128 PPCODE:
1117{ 1129{
1118 dREQ; 1130 dREQ;
1119 1131
1120 req->type = EIO_OPEN; 1132 req->type = EIO_OPEN;
1124 1136
1125 REQ_SEND; 1137 REQ_SEND;
1126} 1138}
1127 1139
1128void 1140void
1129aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1141aio_fsync (SV *fh, SV *callback = &PL_sv_undef)
1130 ALIAS: 1142 ALIAS:
1131 aio_fsync = EIO_FSYNC 1143 aio_fsync = EIO_FSYNC
1132 aio_fdatasync = EIO_FDATASYNC 1144 aio_fdatasync = EIO_FDATASYNC
1133 aio_syncfs = EIO_SYNCFS 1145 aio_syncfs = EIO_SYNCFS
1134 PPCODE: 1146 PPCODE:
1142 1154
1143 REQ_SEND; 1155 REQ_SEND;
1144} 1156}
1145 1157
1146void 1158void
1147aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 1159aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback = &PL_sv_undef)
1148 PPCODE: 1160 PPCODE:
1149{ 1161{
1150 int fd = s_fileno_croak (fh, 0); 1162 int fd = s_fileno_croak (fh, 0);
1151 dREQ; 1163 dREQ;
1152 1164
1159 1171
1160 REQ_SEND; 1172 REQ_SEND;
1161} 1173}
1162 1174
1163void 1175void
1164aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) 1176aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback = &PL_sv_undef)
1165 PPCODE: 1177 PPCODE:
1166{ 1178{
1167 int fd = s_fileno_croak (fh, 0); 1179 int fd = s_fileno_croak (fh, 0);
1168 dREQ; 1180 dREQ;
1169 1181
1176 1188
1177 REQ_SEND; 1189 REQ_SEND;
1178} 1190}
1179 1191
1180void 1192void
1181aio_close (SV *fh, SV *callback=&PL_sv_undef) 1193aio_close (SV *fh, SV *callback = &PL_sv_undef)
1182 PPCODE: 1194 PPCODE:
1183{ 1195{
1184 static int close_fd = -1; /* dummy fd to close fds via dup2 */ 1196 static int close_fd = -1; /* dummy fd to close fds via dup2 */
1185 int fd = s_fileno_croak (fh, 0); 1197 int fd = s_fileno_croak (fh, 0);
1186 dREQ; 1198 dREQ;
1210 1222
1211 REQ_SEND; 1223 REQ_SEND;
1212} 1224}
1213 1225
1214void 1226void
1215aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) 1227aio_seek (SV *fh, SV *offset, int whence, SV *callback = &PL_sv_undef)
1216 PPCODE: 1228 PPCODE:
1217{ 1229{
1218 int fd = s_fileno_croak (fh, 0); 1230 int fd = s_fileno_croak (fh, 0);
1219 dREQ; 1231 dREQ;
1220 1232
1226 1238
1227 REQ_SEND; 1239 REQ_SEND;
1228} 1240}
1229 1241
1230void 1242void
1231aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 1243aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback = &PL_sv_undef)
1232 ALIAS: 1244 ALIAS:
1233 aio_read = EIO_READ 1245 aio_read = EIO_READ
1234 aio_write = EIO_WRITE 1246 aio_write = EIO_WRITE
1235 PPCODE: 1247 PPCODE:
1236{ 1248{
1252 len = svlen - dataoffset; 1264 len = svlen - dataoffset;
1253 } 1265 }
1254 else 1266 else
1255 { 1267 {
1256 /* read: check type and grow scalar as necessary */ 1268 /* read: check type and grow scalar as necessary */
1257 SvUPGRADE (data, SVt_PV);
1258 if (SvLEN (data) >= SvCUR (data)) 1269 if (!SvPOK (data) || SvLEN (data) >= SvCUR (data))
1259 svptr = SvGROW (data, len + dataoffset + 1); 1270 svptr = sv_grow (data, len + dataoffset + 1);
1260 else if (SvCUR (data) < len + dataoffset) 1271 else if (SvCUR (data) < len + dataoffset)
1261 croak ("length + dataoffset outside of scalar, and cannot grow"); 1272 croak ("length + dataoffset outside of scalar, and cannot grow");
1262 } 1273 }
1263 1274
1264 { 1275 {
1282 REQ_SEND; 1293 REQ_SEND;
1283 } 1294 }
1284} 1295}
1285 1296
1286void 1297void
1287aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1298aio_readlink (SV8 *pathname, SV *callback = &PL_sv_undef)
1288 ALIAS: 1299 ALIAS:
1289 aio_readlink = EIO_READLINK 1300 aio_readlink = EIO_READLINK
1290 aio_realpath = EIO_REALPATH 1301 aio_realpath = EIO_REALPATH
1291 PPCODE: 1302 PPCODE:
1292{ 1303{
1297 1308
1298 REQ_SEND; 1309 REQ_SEND;
1299} 1310}
1300 1311
1301void 1312void
1302aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1313aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback = &PL_sv_undef)
1303 PPCODE: 1314 PPCODE:
1304{ 1315{
1305 int ifd = s_fileno_croak (in_fh , 0); 1316 int ifd = s_fileno_croak (in_fh , 0);
1306 int ofd = s_fileno_croak (out_fh, 1); 1317 int ofd = s_fileno_croak (out_fh, 1);
1307 dREQ; 1318 dREQ;
1316 1327
1317 REQ_SEND; 1328 REQ_SEND;
1318} 1329}
1319 1330
1320void 1331void
1321aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1332aio_readahead (SV *fh, off_t offset, size_t length, SV *callback = &PL_sv_undef)
1322 PPCODE: 1333 PPCODE:
1323{ 1334{
1324 int fd = s_fileno_croak (fh, 0); 1335 int fd = s_fileno_croak (fh, 0);
1325 dREQ; 1336 dREQ;
1326 1337
1332 1343
1333 REQ_SEND; 1344 REQ_SEND;
1334} 1345}
1335 1346
1336void 1347void
1337aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) 1348aio_stat (SV8 *fh_or_path, SV *callback = &PL_sv_undef)
1338 ALIAS: 1349 ALIAS:
1339 aio_stat = EIO_STAT 1350 aio_stat = EIO_STAT
1340 aio_lstat = EIO_LSTAT 1351 aio_lstat = EIO_LSTAT
1341 aio_statvfs = EIO_STATVFS 1352 aio_statvfs = EIO_STATVFS
1342 PPCODE: 1353 PPCODE:
1363 RETVAL = makedev (maj, min); 1374 RETVAL = makedev (maj, min);
1364 OUTPUT: 1375 OUTPUT:
1365 RETVAL 1376 RETVAL
1366 1377
1367void 1378void
1368aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1379aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback = &PL_sv_undef)
1369 PPCODE: 1380 PPCODE:
1370{ 1381{
1371 dREQ; 1382 dREQ;
1372 1383
1373 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1384 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1376 1387
1377 REQ_SEND; 1388 REQ_SEND;
1378} 1389}
1379 1390
1380void 1391void
1381aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1392aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback = &PL_sv_undef)
1382 PPCODE: 1393 PPCODE:
1383{ 1394{
1384 dREQ; 1395 dREQ;
1385 1396
1386 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1397 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1388 1399
1389 REQ_SEND; 1400 REQ_SEND;
1390} 1401}
1391 1402
1392void 1403void
1393aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1404aio_chmod (SV8 *fh_or_path, int mode, SV *callback = &PL_sv_undef)
1394 PPCODE: 1405 PPCODE:
1395{ 1406{
1396 dREQ; 1407 dREQ;
1397 1408
1398 req->int2 = mode; 1409 req->int2 = mode;
1400 1411
1401 REQ_SEND; 1412 REQ_SEND;
1402} 1413}
1403 1414
1404void 1415void
1405aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) 1416aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback = &PL_sv_undef)
1406 PPCODE: 1417 PPCODE:
1407{ 1418{
1408 dREQ; 1419 dREQ;
1409 1420
1410 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1421 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1413 1424
1414 REQ_SEND; 1425 REQ_SEND;
1415} 1426}
1416 1427
1417void 1428void
1418aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) 1429aio_readdirx (SV8 *pathname, IV flags, SV *callback = &PL_sv_undef)
1419 PPCODE: 1430 PPCODE:
1420{ 1431{
1421 dREQ; 1432 dREQ;
1422 1433
1423 req->type = EIO_READDIR; 1434 req->type = EIO_READDIR;
1430 1441
1431 REQ_SEND; 1442 REQ_SEND;
1432} 1443}
1433 1444
1434void 1445void
1435aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) 1446aio_mkdir (SV8 *pathname, int mode, SV *callback = &PL_sv_undef)
1436 PPCODE: 1447 PPCODE:
1437{ 1448{
1438 dREQ; 1449 dREQ;
1439 1450
1440 req->type = EIO_MKDIR; 1451 req->type = EIO_MKDIR;
1443 1454
1444 REQ_SEND; 1455 REQ_SEND;
1445} 1456}
1446 1457
1447void 1458void
1448aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1459aio_unlink (SV8 *pathname, SV *callback = &PL_sv_undef)
1449 ALIAS: 1460 ALIAS:
1450 aio_unlink = EIO_UNLINK 1461 aio_unlink = EIO_UNLINK
1451 aio_rmdir = EIO_RMDIR 1462 aio_rmdir = EIO_RMDIR
1452 aio_readdir = EIO_READDIR 1463 aio_readdir = EIO_READDIR
1453 PPCODE: 1464 PPCODE:
1459 1470
1460 REQ_SEND; 1471 REQ_SEND;
1461} 1472}
1462 1473
1463void 1474void
1464aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) 1475aio_link (SV8 *oldpath, SV8 *newpath, SV *callback = &PL_sv_undef)
1465 ALIAS: 1476 ALIAS:
1466 aio_link = EIO_LINK 1477 aio_link = EIO_LINK
1467 aio_symlink = EIO_SYMLINK 1478 aio_symlink = EIO_SYMLINK
1468 aio_rename = EIO_RENAME 1479 aio_rename = EIO_RENAME
1469 PPCODE: 1480 PPCODE:
1478 1489
1479 REQ_SEND; 1490 REQ_SEND;
1480} 1491}
1481 1492
1482void 1493void
1483aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) 1494aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback = &PL_sv_undef)
1484 PPCODE: 1495 PPCODE:
1485{ 1496{
1486 dREQ; 1497 dREQ;
1487 1498
1488 req->type = EIO_MKNOD; 1499 req->type = EIO_MKNOD;
1492 1503
1493 REQ_SEND; 1504 REQ_SEND;
1494} 1505}
1495 1506
1496void 1507void
1497aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1508aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback = &PL_sv_undef)
1498 ALIAS: 1509 ALIAS:
1499 aio_mtouch = EIO_MTOUCH 1510 aio_mtouch = EIO_MTOUCH
1500 aio_msync = EIO_MSYNC 1511 aio_msync = EIO_MSYNC
1501 PPCODE: 1512 PPCODE:
1502{ 1513{
1525 REQ_SEND; 1536 REQ_SEND;
1526 } 1537 }
1527} 1538}
1528 1539
1529void 1540void
1530aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) 1541aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback = &PL_sv_undef)
1531 PPCODE: 1542 PPCODE:
1532{ 1543{
1533 STRLEN svlen; 1544 STRLEN svlen;
1534 char *svptr = SvPVbyte (data, svlen); 1545 char *svptr = SvPVbyte (data, svlen);
1535 UV len = SvUV (length); 1546 UV len = SvUV (length);
1554 REQ_SEND; 1565 REQ_SEND;
1555 } 1566 }
1556} 1567}
1557 1568
1558void 1569void
1559aio_mlockall (IV flags, SV *callback=&PL_sv_undef) 1570aio_mlockall (IV flags, SV *callback = &PL_sv_undef)
1560 PPCODE: 1571 PPCODE:
1561{ 1572{
1562 dREQ; 1573 dREQ;
1563 1574
1564 req->type = EIO_MLOCKALL; 1575 req->type = EIO_MLOCKALL;
1566 1577
1567 REQ_SEND; 1578 REQ_SEND;
1568} 1579}
1569 1580
1570void 1581void
1571aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) 1582aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback = &PL_sv_undef)
1572 PPCODE: 1583 PPCODE:
1573{ 1584{
1574 int fd = s_fileno_croak (fh, 0); 1585 int fd = s_fileno_croak (fh, 0);
1575 dREQ; 1586 dREQ;
1576 1587
1589 1600
1590 REQ_SEND; 1601 REQ_SEND;
1591} 1602}
1592 1603
1593void 1604void
1594aio_busy (double delay, SV *callback=&PL_sv_undef) 1605aio_busy (double delay, SV *callback = &PL_sv_undef)
1595 PPCODE: 1606 PPCODE:
1596{ 1607{
1597 dREQ; 1608 dREQ;
1598 1609
1599 req->type = EIO_BUSY; 1610 req->type = EIO_BUSY;
1601 1612
1602 REQ_SEND; 1613 REQ_SEND;
1603} 1614}
1604 1615
1605void 1616void
1606aio_group (SV *callback=&PL_sv_undef) 1617aio_group (SV *callback = &PL_sv_undef)
1607 PPCODE: 1618 PPCODE:
1608{ 1619{
1609 dREQ; 1620 dREQ;
1610 1621
1611 req->type = EIO_GROUP; 1622 req->type = EIO_GROUP;
1612 1623
1624 PUTBACK;
1613 req_submit (req); 1625 req_submit (req);
1626 SPAGAIN;
1627
1614 XPUSHs (req_sv (req, aio_grp_stash)); 1628 XPUSHs (req_sv (req, aio_grp_stash));
1615} 1629}
1616 1630
1617void 1631void
1618aio_nop (SV *callback=&PL_sv_undef) 1632aio_nop (SV *callback = &PL_sv_undef)
1619 ALIAS: 1633 ALIAS:
1620 aio_nop = EIO_NOP 1634 aio_nop = EIO_NOP
1621 aio_sync = EIO_SYNC 1635 aio_sync = EIO_SYNC
1622 PPCODE: 1636 PPCODE:
1623{ 1637{
1627 1641
1628 REQ_SEND; 1642 REQ_SEND;
1629} 1643}
1630 1644
1631int 1645int
1632aioreq_pri (int pri = 0) 1646aioreq_pri (int pri = NO_INIT)
1633 CODE: 1647 CODE:
1634 RETVAL = next_pri; 1648 RETVAL = next_pri;
1635 if (items > 0) 1649 if (items > 0)
1636 { 1650 {
1637 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1651 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1727 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1741 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1728 OUTPUT: 1742 OUTPUT:
1729 RETVAL 1743 RETVAL
1730 1744
1731void 1745void
1732mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) 1746mmap (SV *scalar, STRLEN length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0)
1733 PPCODE: 1747 PPCODE:
1734 sv_unmagic (scalar, MMAP_MAGIC); 1748 sv_unmagic (scalar, MMAP_MAGIC);
1735{ 1749{
1736 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1750 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1737 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1751 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1764munmap (SV *scalar) 1778munmap (SV *scalar)
1765 CODE: 1779 CODE:
1766 sv_unmagic (scalar, MMAP_MAGIC); 1780 sv_unmagic (scalar, MMAP_MAGIC);
1767 1781
1768int 1782int
1769madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 1783madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1770 ALIAS: 1784 ALIAS:
1771 mprotect = 1 1785 mprotect = 1
1772 CODE: 1786 CODE:
1773{ 1787{
1774 STRLEN svlen; 1788 STRLEN svlen;
1775 void *addr = SvPVbyte (scalar, svlen); 1789 void *addr = SvPVbyte (scalar, svlen);
1776 size_t len = SvUV (length); 1790 STRLEN len = SvUV (length);
1777 1791
1778 if (offset < 0) 1792 if (offset < 0)
1779 offset += svlen; 1793 offset += svlen;
1780 1794
1781 if (offset < 0 || offset > svlen) 1795 if (offset < 0 || offset > svlen)
1795} 1809}
1796 OUTPUT: 1810 OUTPUT:
1797 RETVAL 1811 RETVAL
1798 1812
1799int 1813int
1800munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) 1814munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef)
1801 CODE: 1815 CODE:
1802{ 1816{
1803 STRLEN svlen; 1817 STRLEN svlen;
1804 void *addr = SvPVbyte (scalar, svlen); 1818 void *addr = SvPVbyte (scalar, svlen);
1805 size_t len = SvUV (length); 1819 size_t len = SvUV (length);
1861#else 1875#else
1862 RETVAL = EIO_ENOSYS (); 1876 RETVAL = EIO_ENOSYS ();
1863#endif 1877#endif
1864 OUTPUT: 1878 OUTPUT:
1865 RETVAL 1879 RETVAL
1880
1881int
1882pipesize (aio_rfd rfh, int new_size = -1)
1883 PROTOTYPE: $;$
1884 CODE:
1885#if defined(F_SETPIPE_SZ) && defined(F_GETPIPE_SZ)
1886 if (new_size >= 0)
1887 RETVAL = fcntl (rfh, F_SETPIPE_SZ, new_size);
1888 else
1889 RETVAL = fcntl (rfh, F_GETPIPE_SZ);
1890#else
1891 errno = ENOSYS;
1892 RETVAL = -1;
1893#endif
1894 OUTPUT:
1895 RETVAL
1896
1897void
1898pipe2 (int flags = 0)
1899 PROTOTYPE: ;$
1900 PPCODE:
1901{
1902 int fd[2];
1903 int res;
1904
1905 if (flags)
1906#if HAVE_PIPE2
1907 res = pipe2 (fd, flags);
1908#else
1909 res = (errno = ENOSYS, -1);
1910#endif
1911 else
1912 res = pipe (fd);
1913
1914 if (!res)
1915 {
1916 EXTEND (SP, 2);
1917 PUSHs (newmortalFH (fd[0], O_RDONLY));
1918 PUSHs (newmortalFH (fd[1], O_WRONLY));
1919 }
1920}
1866 1921
1867void _on_next_submit (SV *cb) 1922void _on_next_submit (SV *cb)
1868 CODE: 1923 CODE:
1869 SvREFCNT_dec (on_next_submit); 1924 SvREFCNT_dec (on_next_submit);
1870 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1925 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1905cancel (aio_req_ornot req) 1960cancel (aio_req_ornot req)
1906 CODE: 1961 CODE:
1907 eio_cancel (req); 1962 eio_cancel (req);
1908 1963
1909void 1964void
1910cb (aio_req_ornot req, SV *callback=&PL_sv_undef) 1965cb (aio_req_ornot req, SV *callback = NO_INIT)
1911 PPCODE: 1966 PPCODE:
1912{ 1967{
1913 if (GIMME_V != G_VOID) 1968 if (GIMME_V != G_VOID)
1914 XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); 1969 XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef);
1915 1970
1916 if (items > 1) 1971 if (items > 1)
1917 { 1972 {
1918 SV *cb_cv =get_cb (callback); 1973 SV *cb_cv = get_cb (callback);
1919 1974
1920 SvREFCNT_dec (req->callback); 1975 SvREFCNT_dec (req->callback);
1921 req->callback = SvREFCNT_inc (cb_cv); 1976 req->callback = SvREFCNT_inc (cb_cv);
1922 } 1977 }
1923} 1978}
1980limit (aio_req grp, int limit) 2035limit (aio_req grp, int limit)
1981 CODE: 2036 CODE:
1982 eio_grp_limit (grp, limit); 2037 eio_grp_limit (grp, limit);
1983 2038
1984void 2039void
1985feed (aio_req grp, SV *callback=&PL_sv_undef) 2040feed (aio_req grp, SV *callback = &PL_sv_undef)
1986 CODE: 2041 CODE:
1987{ 2042{
1988 SvREFCNT_dec (grp->sv2); 2043 SvREFCNT_dec (grp->sv2);
1989 grp->sv2 = newSVsv (callback); 2044 grp->sv2 = newSVsv (callback);
1990 grp->feed = aio_grp_feed; 2045 grp->feed = aio_grp_feed;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines