Since events and IO are really linked, and really (kinda, sorta) the
same thing, it seems silly to have two separate documents that spend
half their time referring to the other, and duplicating a lot of
stuff between them. (I've a hard enough time keeping things straight
within a single document, let alone two)
The comments on the first draft that still apply have been
Events and IO
Parrot has a unified event and IO system--indeed events are nothing
The event and IO system revolves around streams, requests, and
Each stream in the event and IO system has the same structure. There
The preprocessing, anchor, and post-processing layers are isolated
The system is simple--you make a request to a stream. The request
Non-IO things such as signals and OS events (assuming we can get to
At the moment each filehandle has a single set of IO layers which
Note that any layer along the way may defer the IO request. A
Layer and Callback functions
Since IO layers and event callbacks are identical, they have the same
(Sreturndata, Icommand) =
The returndata from a layer is passed into the next layer as its
The commands are:
* 1 - Event
Negative command arguments indicate that the command request has had
Requests and events have one of the following statuses:
* Unprocessed - The request has been issued but not yet touched
There are two classses of events and IO requests: solicited and
A solicited event or request is one that a user program has
An unsolicited event, on the other hand, is one that parrot generates
There are four big differences between solicited and unsolicited
1) A solicited event goes through a stream's preprocessing
2) A solicted event may be cancelled from user code, as the user code
3) A solicited event may have a callback and user data associated
4) Any exception associated with a solicited event will be thrown
Interfacing with System Events
It is possible, given the nature of fighting event loops, that parrot
Event Source Methods
The following methods are required of any event source that
Stop the event source from emitting events. Any event that would be
Like pause, except the events are held rather than discarded.
Permanently stop the event source.
Undo a pause or hold on the event source. If any events are pending
The opcodes in this section are a combination of event requests and
Most of the event request ops have two forms, one of which takes a
Explicitly check to see if there are any events pending in the event queue and,
Wait forever, draining the event queue as it fills. This op only
Wait for the specified event to complete. If the event has already
getstat Istatus, Pevent
Returns the status of the event, noting whether it has been completed
getdata Pdata, Pevent
Get the data associated with the event, if there is any. What the data is
getuser Puserdata, Pevent
Get the user data that was passed into this event.
Cancel the request, if possible.
Post an event to the event queue for later handling
sethandler Ieventclass, Phandlersub
Set the default handler for the specified class of events.
Set the current event level. Events of a lower level than this won't
These are the ops that control IO. Note that the synchronous versions
readw mydata, Filehandle, 500
is equivalent to the sequence
read tempevent, Filehandle, 500
but is provided for convenience for those languages which are so
newhandle Pfilehandle, Panchorsub
Create a new filehandle. C<anchorsub> is the subroutine that anchors
pushhandler Pfilehandle, Phandlersub, Ireadwritecontrol
addhandler Pfilehandle, Phandlersub, Ioffset, Ireadwritecontrol
removehandler Pfilehandle, Phandlersub, Ioffset, Ireadwritecontrol
read Pevent, Pfilehandle, Ihowmuch[, Pcallback, Puserdata]
Request a read of data from the filehandle.
readw Pdata, Pfilehandle, Ihowmuch
Synchronously read C<howmuch> data from the filehandle.
write Pevent, Pfilehandle, Pdata[, Pcallback, Puserdata]
Write the data to the filehandle.
writew Pfilehandle, Pdata
Synchronously write the data to the filehandle
seek Pevent, Pfilehandle, Iwhere[, Pcallback, Puserdata]
Submit a request to seek to the specified position in the file.
tell Pevent, Pfilehandle[, Pcallback, Puserdata]
Submit a request for the current position in the filehandle.
un_read Pfilehandle, Pdata
Undo a read request, pushing Pdata back onto the filehandle. (Note
--------------------------------------"it's like this"-------------------
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.