GSoC/GCI Archive
Google Code-in 2010 Parrot Foundation and The Perl Foundation

Add Read and Readline methods to Socket PMC

completed by: Fernando Brito

mentors: whiteknight

Task Description: Parrot's IO system has several major improvements scheduled in the coming months. Before those can happen, the existing system needs to be cleaned up significantly. Code files in src/io/ directory implement much of the low-level IO logic, while special "Handle" object types in src/pmc/ directory provide specific implementations that the user will interact with. These include "FileHandle" (for interacting with files on disk), Socket (for communicating over a network) and StringHandle (for interacting with a string as if it were a file). All three of these PMC types inherit from the Handle type, and should have read and readline methods.

Steps to complete:

  1. Create a fork of parrot/parrot on github
  2. Move the read and readline methods from src/pmc/filehandle.pmc to src/pmc/handle.pmc
  3. Add a new branch to src/io/api.c:Parrot_io_reads() to handle the case of enum_class_Socket. Move the guts of the recv method in src/pmc/socket.pmc into the new branch
  4. Add a branch to src/io/api.c:Parrot_io_readline to handle the case of enum_class_Socket. We aren't ready to implement this, so throw an EXCEPTION_PIO_ERROR exception. Parrot_ex_throw_from_c_args, etc
  5. Change the recv method in src/pmc/socket.pmc to call Parrot_io_reads
  6. Delete the read and readline methods from FileHandle and StringHandle. They should be inherited from Handle
  7. Build parrot and run all tests (make fulltest), fixing any errors that pop up
  8. Add a new test to t/pmc/socket.t to show that it has the read and readline methods. The read method should work the same as recv (feel free to copy the test). the readline method should throw an exception.
  9. open a pull request on github to get your changes merged in.