# Where is the .rb for sockets?

**URL:** <https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443>\
**Category:** Ruby\
**Created:** [July 8, 2008, 1:42am UTC](https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443 "2008-07-08T01:42:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 8, 2008, 1:42am UTC](https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443/1 "2008-07-08T01:42:16Z")

</div>

Normally I use `ri foo` whenever I want to read up on something. There’s  
also the ruby library, (/usr/lib/ruby/1.8), as there are some goodies  
and clues in the comments. `locate foo.rb` normally does it but in the  
case for TCPSocket, Socket and IPSocket there’s nothing to be found.  
Where is it hidden?

Socket.ancestors  
[Socket, BasicSocket, IO, File::Constants, Enumerable, Object,  
PP::ObjectMixin, Kernel]

I’m guessing that it’s either part of IO or something writen in C. Am I  
right? Is there a Socket.rb file anywhere?

- jjm

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 8, 2008, 1:50am UTC](https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443/2 "2008-07-08T01:50:27Z")

</div>

John M. wrote:

> Normally I use `ri foo` whenever I want to read up on something. There’s  
> also the ruby library, (/usr/lib/ruby/1.8), as there are some goodies and clues in the comments. `locate foo.rb` normally does it but in the case for TCPSocket, Socket and IPSocket there’s nothing to be found. Where is it hidden?
> 
> Socket.ancestors  
> [Socket, BasicSocket, IO, File::Constants, Enumerable, Object, PP::ObjectMixin, Kernel]
> 
> I’m guessing that it’s either part of IO or something writen in C. Am I  
> right? Is there a Socket.rb file anywhere?

Socket lib is written in C, but there are ri docs for it:

$ ri Socket | head -n 20  
---------------------------------------------------------- Class: Socket  
Class Socket provides access to the underlying operating system  
socket implementations. It can be used to provide more operating  
system specific functionality than the protocol-specific socket  
classes but at the expense of greater complexity. In particular,  
the class handles addresses using +struct sockaddr+ structures  
packed into Ruby strings, which can be a joy to manipulate.

```
  Exception Handling
  Ruby's implementation of Socket causes an exception to be raised
  based on the error generated by the system dependent
  implementation. This is why the methods are documented in a way
  that isolate Unix-based system exceptions from Windows based
  exceptions. If more information on particular exception is needed
  please refer to the Unix manual pages or the Windows WinSock
  reference.

  Documentation by
  * Zach D.

```

Does this work on your system?

Not all of the methods have docs, tho.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 8, 2008, 2:00am UTC](https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443/3 "2008-07-08T02:00:58Z")

</div>

On Tue, 8 Jul 2008 08:46:25 +0900  
Joel VanderWerf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> ```
> system specific functionality than the protocol-specific socket
> 
> ```
> 
> needed please refer to the Unix manual pages or the Windows WinSock  
> reference.
> 
> ```
> Documentation by
> * Zach D.
> 
> ```
> 
> Does this work on your system?
> 
> Not all of the methods have docs, tho.

yes that does work. I have those docs. where is the c code for io or tcp  
stuff? it it not this stuff…

/home/jayeola/bx/rb/ruby/1.8/io:  
total used in directory 12 available 16697500  
drwxr-xr-x 2 jayeola jayeola 4096 2008-06-27 03:30 .  
drwxr-xr-x 31 jayeola jayeola 4096 2008-07-06 10:53 …  
-rw-r–r-- 1 jayeola jayeola 408 2008-06-27 03:30 nonblock.rb

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 8, 2008, 7:27am UTC](https://www.ruby-forum.com/t/where-is-the-rb-for-sockets/142443/4 "2008-07-08T07:27:04Z")

</div>

On 7/8/08, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Tue, 8 Jul 2008 08:46:25 +0900  
> Joel VanderWerf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > John M. wrote:
> > 
> > > Normally I use `ri foo` whenever I want to read up on something.  
> > > There’s also the ruby library, (/usr/lib/ruby/1.8), as there are  
> > > some goodies and clues in the comments. `locate foo.rb` normally  
> > > does it but in the case for TCPSocket, Socket and IPSocket there’s  
> > > nothing to be found. Where is it hidden?

You are looking for ‘socket.c’, which can be found in the ext/socket  
directory:  
[http://github.com/rubyspec/matzruby/tree/ebe2c2934c3fecfd4751eeeb256bf7293cdc9654/ext/socket/socket.c](http://github.com/rubyspec/matzruby/tree/ebe2c2934c3fecfd4751eeeb256bf7293cdc9654/ext/socket/socket.c)
