Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F3997526
TSocketServer.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 8, 9:48 PM
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Jul 10, 9:48 PM (1 d, 10 h)
Engine
blob
Format
Raw Data
Handle
272444
Attached To
rXR Xreate
TSocketServer.php
View Options
<?php
namespace
Thrift
\
Transport
;
use
Thrift
\
Exception
\
TException
;
use
Thrift
\
Factory
\
TStringFuncFactory
;
class
TSocketServer
extends
TTransport
{
private
$address
=
null
;
private
$client
=
null
;
private
$server
=
null
;
public
function
__construct
(
$address
)
{
$this
->
address
=
$address
;
}
public
function
open
(
)
{
$this
->
server
=
stream_socket_server
(
$this
->
address
,
$errno
,
$errorMessage
)
;
if
(
$this
->
server
===
false
)
{
throw
new
TException
(
"Could not bind to socket: $errorMessage"
)
;
}
$this
->
client
=
@
stream_socket_accept
(
$this
->
server
,
3600
)
;
if
(
!
$this
->
client
)
{
throw
new
TException
(
"Could not accept connection"
)
;
}
}
public
function
close
(
)
{
fclose
(
$this
->
client
)
;
}
public
function
isOpen
(
)
{
return
!
is_null
(
$client
)
;
}
public
function
read
(
$len
)
{
do
{
$data
=
@
fread
(
$this
->
client
,
$len
)
;
}
while
(
$data
===
FALSE
||
$data
===
''
)
;
return
$data
;
}
public
function
write
(
$buf
)
{
while
(
TStringFuncFactory
::
create
(
)
->
strlen
(
$buf
)
>
0
)
{
$got
=
@
fwrite
(
$this
->
client
,
$buf
)
;
if
(
$got
===
0
||
$got
===
FALSE
)
{
throw
new
TException
(
'TPhpStream: Could not write '
.
TStringFuncFactory
::
create
(
)
->
strlen
(
$buf
)
.
' bytes'
)
;
}
$buf
=
TStringFuncFactory
::
create
(
)
->
substr
(
$buf
,
$got
)
;
}
}
public
function
flush
(
)
{
@
fflush
(
$this
->
client
)
;
}
}
Event Timeline
Log In to Comment