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

Revision 151, 2.4 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).

  • Property svn:eol-style set to native
  • Property svn:executable set to *
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                if ( $socket = @stream_socket_client($pSocket, $errno, $errstr) )
26                {
27                        #stream_set_blocking($socket, $pBlockingMode);
28                        #stream_set_timeout($socket, $pTimeOut);
29                        stream_set_blocking($socket, 1);
30                        stream_set_timeout($socket, 1);
31                }
32                return $socket;
33        }
34
35        protected final function blocking($pSocket = false, $pBlockingMode = 1)
36        {
37                if ( !$pSocket || !is_resource($pSocket) )
38                        return false;
39
40                stream_set_blocking($pSocket, $pBlockingMode);
41        }
42
43
44        protected function read( $pSocket = false, $pLength = 4096 )
45        {
46                ini_set( 'track_errors', '1' );
47                $php_errormsg = '';
48
49                if ( !$pSocket || !is_resource($pSocket) )
50                        return false;
51
52                set_magic_quotes_runtime(0);
53                $return = @fread($pSocket, $pLength);
54                set_magic_quotes_runtime(get_magic_quotes_gpc());
55
56
57                if ( $php_errormsg )
58                        return false;
59
60                return $return;
61        }
62
63        protected function write( $pSocket = false, $pData = false )
64        {
65                ini_set( 'track_errors', '1' );
66                $php_errormsg = '';
67
68                if ( (!$pSocket || !is_resource($pSocket)) || !$pData )
69                        return false;
70
71                $return = @fwrite($pSocket, $pData);
72
73                if ( $php_errormsg )
74                        return false;
75
76                return $return;
77        }
78
79        protected final function close( $pSocket = false )
80        {
81                if ( !$pSocket || !is_resource($pSocket) )
82                        return false;
83
84                return fclose($pSocket);
85        }
86}
87?>
Note: See TracBrowser for help on using the repository browser.