Update: I've managed to get it working - the C code now passes in a real filehandle glob which is already blessed to IO::Socket::INET. However, I'm not entirely sure that my code to do so is entirely sane and correct. It's more or less what I managed to cobble together by reading the source to pp_socket in pp_sys.c and staring at the perlapi/perlguts/etc docs. I don't entirely understand the purpose of some things, and I'm not sure that I'm not leaking memory:
[...]
IO* conn_pio;
SV* connrv;
GV* fhglob;
HV* our_stash;
HV* isn_stash;
isn_stash = gv_stashpv("IO::Socket::INET",1);
our_stash = gv_stashpv("MyModule::Name",1);
fhglob = gv_fetchmethod(our_stash,"myfilehandle");
conn_pio = GvIOn(fhglob);
IoIFP(conn_pio) = PerlIO_fdopen(conn, "r"SOCKET_OPEN_MODE);
IoOFP(conn_pio) = PerlIO_fdopen(conn, "w"SOCKET_OPEN_MODE);
IoTYPE(conn_pio) = IoTYPE_SOCKET;
connrv = newRV_inc((SV*)fhglob);
sv_bless(connrv,isn_stash);
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(connrv);
PUTBACK;
cpretval = call_sv(kid_conn_coderef, G_SCALAR|G_EVAL|G_KEEPERR);
[....]
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.