nanoserv
[ class tree: nanoserv ] [ index: nanoserv ] [ all elements ]

Class: NS_Socket

Source Location: /nanoserv.php

Class Overview


Base socket class


Author(s):

Variables

Constants

Methods


Child classes:

NS_Server_Socket
Server socket class
NS_Client_Socket
Client socket class
NS_IPC_Socket
IPC Socket class

Class Details

[line 103]
Base socket class



Tags:

since:  0.9


[ Top ]


Class Variables

$blocked =  false

[line 145]

Is the socket blocked ?



Tags:

access:  public

Type:   bool


[ Top ]

$block_reads =  false

[line 151]

Should we block reading from this socket ?



Tags:

access:  public

Type:   bool


[ Top ]

$connected =  false

[line 127]

Is the socket connected ?



Tags:

access:  public

Type:   bool


[ Top ]

$context =

[line 157]

Stream context



Tags:

access:  protected

Type:   resource


[ Top ]

$crypto_type =

[line 163]

Crypto type



Tags:

access:  public

Type:   int


[ Top ]

$fd =

[line 121]

Socket stream descriptor



Tags:

access:  public

Type:   resource


[ Top ]

$handler =

[line 169]

Attached handler



Tags:

access:  public



[ Top ]

$id =

[line 115]

Internal Socket unique ID



Tags:

access:  public

Type:   int


[ Top ]

$pending_connect =  false

[line 133]

Is the socket waiting to be connected ?



Tags:

access:  public

Type:   bool


[ Top ]

$pending_crypto =  false

[line 139]

Is the socket waiting for ssl/tls handshake ?



Tags:

access:  public

Type:   bool


[ Top ]



Class Methods


constructor __construct [line 182]

NS_Socket __construct( [resource $fd = false], [ $crypto_type = false])

NS_Socket contructor



Tags:

access:  public


Overridden in child classes as:

NS_Server_Socket::__construct()
NS_Server_Socket constructor
NS_Client_Socket::__construct()
NS_Client_Socket constructor
NS_IPC_Socket::__construct()
IPC Socket constructor

Parameters:

resource   $fd  
   $crypto_type  

[ Top ]

destructor __destruct [line 471]

void __destruct( )

NS_Socket destructor



Tags:

access:  public


[ Top ]

method Block_Reads [line 281]

bool Block_Reads( bool $block)

Flag the socket so that the main loop won't read from it even if data is available.

This can be used to implement flow control when proxying data between two asymetric connections for example.




Tags:

return:  the previous status
since:  2.0.3
access:  public


Parameters:

bool   $block  

[ Top ]

method Close [line 460]

void Close( )

Close the socket



Tags:

since:  0.9
access:  public


[ Top ]

method Enable_Crypto [line 312]

mixed Enable_Crypto( [bool $enable = true], [int $type = false])

Enable or disable ssl/tls crypto on the socket



Tags:

since:  0.9
access:  public


Parameters:

bool   $enable  
int   $type  

[ Top ]

method Eof [line 444]

bool Eof( )

Query end of stream status



Tags:

since:  0.9
access:  public


[ Top ]

method Get_Name [line 344]

string Get_Name( )

Get local socket name



Tags:

since:  0.9
access:  public


[ Top ]

method Get_Options [line 209]

array Get_Options( )

Get stream options



Tags:

since:  0.9
access:  public


[ Top ]

method Get_Peer_Name [line 356]

string Get_Peer_Name( )

Get remote socket name



Tags:

since:  0.9
access:  public


[ Top ]

method Read [line 369]

string Read( int $length)

Read data from the socket and return it



Tags:

since:  0.9
access:  public


Overridden in child classes as:

NS_IPC_Socket::Read()
Read data from IPC socket

Parameters:

int   $length   maximum read length

[ Top ]

method Read_From [line 383]

string Read_From( string &$addr, [int $len = 16384])

Read data from a non connected socket and return it



Tags:

since:  0.9.61
access:  public


Parameters:

string   &$addr   contains the message sender address upon return
int   $len   maximum read length

[ Top ]

method Setup [line 330]

bool Setup( )

Setup crypto if needed



Tags:

since:  0.9
access:  public


[ Top ]

method Set_Blocking [line 266]

bool Set_Blocking( bool $block)

Sets wether the socket is blocking or not



Tags:

since:  0.9
access:  protected


Parameters:

bool   $block  

[ Top ]

method Set_Option [line 232]

bool Set_Option( string $wrapper, string $opt, mixed $val)

Set a stream context option



Tags:

since:  0.9
access:  public


Parameters:

string   $wrapper  
string   $opt  
mixed   $val  

[ Top ]

method Set_Timeout [line 253]

bool Set_Timeout( int $timeout)

Set timeout



Tags:

since:  0.9
access:  protected


Parameters:

int   $timeout  

[ Top ]

method Set_Write_Buffer [line 298]

int Set_Write_Buffer( int $buffer_size)

Set the stream write buffer (PHP defaults to 8192 bytes)



Tags:

since:  2.0
access:  public


Parameters:

int   $buffer_size  

[ Top ]

method Write [line 398]

int Write( string $data)

Write data to the socket

write returns the number of bytes written to the socket




Tags:

since:  0.9
access:  public


Parameters:

string   $data  

[ Top ]

method Write_From_Stream [line 432]

int Write_From_Stream( resource $stream, [int $len = 16384])

Write data from stream to socket

returns the number of bytes read from the stream and written to the socket




Tags:

since:  2.1
access:  public


Parameters:

resource   $stream  
int   $len   maximum length (bytes) to read/write

[ Top ]

method Write_To [line 416]

int Write_To( string $to, string $data)

Write data to a non connected socket



Tags:

since:  0.9.61
access:  public


Parameters:

string   $to   in the form of "<ip_address>:<port>"
string   $data  

[ Top ]


Class Constants

DEFAULT_READ_LENGTH =  16384

[line 109]

Maximum number of bytes read by Read()


[ Top ]



Documentation generated on Thu, 10 May 2012 22:01:24 +0200 by phpDocumentor 1.4.4