source: trunk/instant_messenger/bkp/instant_messenger_64/inc/Socket.abstract.php @ 151

Revision 151, 2.5 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Line 
1<?php
2/*
3+-------------------------------------------------------------------------+
4|                                                                         |
5| @FILE_NAME:   Socket.abstract.php                                       |
6| @CLASS_NAME:  (abstract) Jabber                                         |
7|                                                                         |
8| @DATE:        Wed May,16 2007 07:58:59                                  |
9| @LAST_CHANGE: Wed May,16 2007 08:03:28                                  |
10|                                                                         |
11| @AUTHOR:      [NUTS] Rodrigo Souza - rodsouza@celepar.pr.gov.br         |
12|                                                                         |
13| @BRIEF:       Abstract class for connect with a socket                  |
14|                                                                         |
15+-------------------------------------------------------------------------+
16*/
17
18abstract class Socket
19{
20        protected final function open( $pSocket = false, $pTimeOut = 1, $pBlockingMode = 0 )
21        {
22      if ( !$pSocket )
23         return false;
24
25                $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
26
27      $pSocket = substr($pSocket, 6);
28      if ( $socket = socket_connect($sock, substr($pSocket, 0, strpos($pSocket, ":")), substr($pSocket, strpos($pSocket, ":") + 1)) )
29      {
30         socket_set_block($sock);
31      }
32
33      return $sock;
34        }
35
36   protected final function blocking($pSocket = false, $pBlockingMode = 1)
37   {
38      if ( !$pSocket || !is_resource($pSocket) )
39         return false;
40
41      if ( $pBlockingMode == 1 )
42        socket_set_block($pSocket);
43                else
44                        socket_set_nonblock($pSocket);
45   }
46
47        protected function read( $pSocket = false, $pLength = 4096 )
48        {
49      ini_set( 'track_errors', '1' );
50
51      if ( !$pSocket || !is_resource($pSocket) )
52         return false;
53
54      $return = socket_read($pSocket, $pLength);
55
56      if ( $php_errormsg )
57         return false;
58
59      return $return;
60        }
61
62        protected function write( $pSocket = false, $pData = false )
63        {
64      ini_set( 'track_errors', '1' );
65     
66      if ( (!$pSocket || !is_resource($pSocket)) || !$pData )
67         return false;
68
69                $return = @socket_write($pSocket, $pData);
70     
71      if ( $php_errormsg )
72         return false;
73
74      return $return;
75        }
76
77        protected final function close( $pSocket = false )
78        {
79      if ( !$pSocket || !is_resource($pSocket) )
80         return false;
81
82                return socket_close($pSocket);
83        }
84}
85?>
Note: See TracBrowser for help on using the repository browser.