Soup.Socket¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
The |
||
r/w/co |
The socket’s file descriptor |
||
w/co |
The socket’s underlying |
||
w/co |
The socket’s underlying |
||
r/w |
IPv6 only |
||
r |
Whether or not the socket is a server socket |
||
r/w/co |
Address of local end of socket |
||
r/w |
Whether or not the socket uses non-blocking I/O |
||
r/w/co |
Address of remote end of socket |
||
r/w |
SSL credential information, passed from the session to the SSL implementation |
||
r/w/co |
Use SSLv3 instead of TLS (client-side only) |
||
r/w/co |
Whether certificate errors should be considered a connection error |
||
r/w |
Value in seconds to timeout a blocking I/O |
||
r |
The peer’s TLS certificate |
||
r |
Errors with the peer’s TLS certificate |
||
r |
Whether the server certificate is trusted, if this is an SSL socket |
||
r/w/co |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when the socket is disconnected, for whatever reason. |
|
Emitted when a network-related event occurs. |
|
Emitted when a listening socket (set up with |
|
Emitted when an async socket is readable. |
|
Emitted when an async socket is writable. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class Soup.Socket(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- connect_async(cancellable, callback, *user_data)¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Soup.SocketCallback
) – callback to call after connecting
Begins asynchronously connecting to self's remote address. The socket will call callback when it succeeds or fails (but not before returning from this function).
If cancellable is non-
None
, it can be used to cancel the connection. callback will still be invoked in this case, with a status ofSoup.Status.CANCELLED
.
- connect_sync(cancellable)¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Returns:
a success or failure code.
- Return type:
Attempt to synchronously connect self to its remote address.
If cancellable is non-
None
, it can be used to cancel the connection, in which caseSoup.Socket.connect_sync
() will returnSoup.Status.CANCELLED
.
- disconnect()¶
Disconnects self. Any further read or write attempts on it will fail.
- get_fd()¶
- Returns:
self's file descriptor.
- Return type:
Gets self's underlying file descriptor.
Note that fiddling with the file descriptor may break the
Soup.Socket
.
- get_local_address()¶
- Returns:
the
Soup.Address
- Return type:
Returns the
Soup.Address
corresponding to the local end of self.Calling this method on an unconnected socket is considered to be an error, and produces undefined results.
- get_remote_address()¶
- Returns:
the
Soup.Address
- Return type:
Returns the
Soup.Address
corresponding to the remote end of self.Calling this method on an unconnected socket is considered to be an error, and produces undefined results.
- is_connected()¶
-
Tests if self is connected to another host
- is_ssl()¶
-
Tests if self is doing (or has attempted to do) SSL.
- listen()¶
- Returns:
whether or not self is now listening.
- Return type:
Makes self start listening on its local address. When connections come in, self will emit #SoupSocket::new_connection.
- read(buffer, cancellable)¶
- Parameters:
buffer (
bytes
) – buffer to read intocancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a
Soup.SocketIOStatus
, as described above (orSoup.SocketIOStatus.EOF
if the socket is no longer connected, orSoup.SocketIOStatus.ERROR
on any other error, in which case error will also be set).- nread:
on return, the number of bytes read into buffer
- Return type:
(
Soup.SocketIOStatus
, nread:int
)
Attempts to read up to len bytes from self into buffer. If some data is successfully read,
Soup.Socket.read
() will returnSoup.SocketIOStatus.OK
, and nread will contain the number of bytes actually read (which may be less than len).If self is non-blocking, and no data is available, the return value will be
Soup.SocketIOStatus.WOULD_BLOCK
. In this case, the caller can connect to theSoup.Socket
::readable
signal to know when there is more data to read. (NB: You MUST read all available data off the socket first.Soup.Socket
::readable
is only emitted afterSoup.Socket.read
() returnsSoup.SocketIOStatus.WOULD_BLOCK
, and it is only emitted once. See the documentation forSoup.Socket
:non-blocking
.)
- read_until(buffer, boundary, boundary_len, cancellable)¶
- Parameters:
buffer (
bytes
) – buffer to read intoboundary_len (
int
) – length of boundary in bytescancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
as for
Soup.Socket.read
()- nread:
on return, the number of bytes read into buffer
- got_boundary:
on return, whether or not the data in buffer ends with the boundary string
- Return type:
(
Soup.SocketIOStatus
, nread:int
, got_boundary:bool
)
Like
Soup.Socket.read
(), but reads no further than the first occurrence of boundary. (If the boundary is found, it will be included in the returned data, and got_boundary will be set toTrue
.) Any data after the boundary will returned in future reads.Soup.Socket.read_until
() will almost always return fewer than len bytes: if the boundary is found, then it will only return the bytes up until the end of the boundary, and if the boundary is not found, then it will leave the last(boundary_len - 1)
bytes in its internal buffer, in case they form the start of the boundary string. Thus, len normally needs to be at least 1 byte longer than boundary_len if you want to make any progress at all.
- start_proxy_ssl(ssl_host, cancellable)¶
- Parameters:
ssl_host (
str
) – hostname of the SSL servercancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Returns:
success or failure
- Return type:
Starts using SSL on socket, expecting to find a host named ssl_host.
- start_ssl(cancellable)¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Returns:
success or failure
- Return type:
Starts using SSL on socket.
- write(buffer, cancellable)¶
- Parameters:
buffer (
bytes
) – data to writecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a
Soup.SocketIOStatus
, as described above (orSoup.SocketIOStatus.EOF
orSoup.SocketIOStatus.ERROR
. error will be set if the return value isSoup.SocketIOStatus.ERROR
.)- nwrote:
on return, number of bytes written
- Return type:
(
Soup.SocketIOStatus
, nwrote:int
)
Attempts to write len bytes from buffer to self. If some data is successfully written, the return status will be
Soup.SocketIOStatus.OK
, and nwrote will contain the number of bytes actually written (which may be less than len).If self is non-blocking, and no data could be written right away, the return value will be
Soup.SocketIOStatus.WOULD_BLOCK
. In this case, the caller can connect to theSoup.Socket
::writable
signal to know when more data can be written. (NB:Soup.Socket
::writable
is only emitted afterSoup.Socket.write
() returnsSoup.SocketIOStatus.WOULD_BLOCK
, and it is only emitted once. See the documentation forSoup.Socket
:non-blocking
.)
- do_disconnected() virtual¶
- do_new_connection(new_sock) virtual¶
- Parameters:
new_sock (
Soup.Socket
) –
- do_readable() virtual¶
- do_writable() virtual¶
Signal Details¶
- Soup.Socket.signals.disconnected(socket)¶
- Signal Name:
disconnected
- Flags:
- Parameters:
socket (
Soup.Socket
) – The object which received the signal
Emitted when the socket is disconnected, for whatever reason.
- Soup.Socket.signals.event(socket, event, connection)¶
- Signal Name:
event
- Flags:
- Parameters:
socket (
Soup.Socket
) – The object which received the signalevent (
Gio.SocketClientEvent
) – the event that occurredconnection (
Gio.IOStream
) – the current connection state
Emitted when a network-related event occurs. See
Gio.SocketClient
::event
for more details.New in version 2.38.
- Soup.Socket.signals.new_connection(socket, new)¶
- Signal Name:
new-connection
- Flags:
- Parameters:
socket (
Soup.Socket
) – The object which received the signalnew (
Soup.Socket
) – the new socket
Emitted when a listening socket (set up with
Soup.Socket.listen
()) receives a new connection.You must ref the new if you want to keep it; otherwise it will be destroyed after the signal is emitted.
- Soup.Socket.signals.readable(socket)¶
- Signal Name:
readable
- Flags:
- Parameters:
socket (
Soup.Socket
) – The object which received the signal
Emitted when an async socket is readable. See
Soup.Socket.read
(),Soup.Socket.read_until
() andSoup.Socket
:non-blocking
.
- Soup.Socket.signals.writable(socket)¶
- Signal Name:
writable
- Flags:
- Parameters:
socket (
Soup.Socket
) – The object which received the signal
Emitted when an async socket is writable. See
Soup.Socket.write
() andSoup.Socket
:non-blocking
.
Property Details¶
- Soup.Socket.props.async_context¶
- Name:
async-context
- Type:
- Default Value:
- Flags:
The
GLib.MainContext
to dispatch this socket’s async I/O in
- Soup.Socket.props.fd¶
- Name:
fd
- Type:
- Default Value:
-1
- Flags:
The socket’s file descriptor
- Soup.Socket.props.gsocket¶
- Name:
gsocket
- Type:
- Default Value:
- Flags:
The socket’s underlying
Gio.Socket
- Soup.Socket.props.iostream¶
- Name:
iostream
- Type:
- Default Value:
- Flags:
The socket’s underlying
Gio.IOStream
- Soup.Socket.props.ipv6_only¶
-
IPv6 only
- Soup.Socket.props.is_server¶
-
Whether or not the socket is a server socket.
Note that for “ordinary”
Soup.Sockets
this will be set for both listening sockets and the sockets emitted bySoup.Socket
::new-connection
, but for sockets created by settingSoup.Socket
:fd
, it will only be set for listening sockets.
- Soup.Socket.props.local_address¶
- Name:
local-address
- Type:
- Default Value:
- Flags:
Address of local end of socket
- Soup.Socket.props.non_blocking¶
-
Whether or not the socket uses non-blocking I/O.
Soup.Socket
's I/O methods are designed around the idea of using a single codepath for both synchronous and asynchronous I/O. If you want to read off aSoup.Socket
, the “correct” way to do it is to callSoup.Socket.read
() orSoup.Socket.read_until
() repeatedly until you have read everything you want. If it returnsSoup.SocketIOStatus.WOULD_BLOCK
at any point, stop reading and wait for it to emit theSoup.Socket
::readable
signal. Then go back to the reading-as-much-as-you-can loop. Likewise, for writing to aSoup.Socket
, you should callSoup.Socket.write
() either until you have written everything, or it returnsSoup.SocketIOStatus.WOULD_BLOCK
(in which case you wait forSoup.Socket
::writable
and then go back into the loop).Code written this way will work correctly with both blocking and non-blocking sockets; blocking sockets will simply never return
Soup.SocketIOStatus.WOULD_BLOCK
, and so the code that handles that case just won’t get used for them.
- Soup.Socket.props.remote_address¶
- Name:
remote-address
- Type:
- Default Value:
- Flags:
Address of remote end of socket
- Soup.Socket.props.ssl_creds¶
-
SSL credential information, passed from the session to the SSL implementation
- Soup.Socket.props.ssl_fallback¶
- Name:
ssl-fallback
- Type:
- Default Value:
- Flags:
Use SSLv3 instead of TLS (client-side only)
- Soup.Socket.props.ssl_strict¶
- Name:
ssl-strict
- Type:
- Default Value:
- Flags:
Whether certificate errors should be considered a connection error
- Soup.Socket.props.timeout¶
-
Value in seconds to timeout a blocking I/O
- Soup.Socket.props.tls_certificate¶
- Name:
tls-certificate
- Type:
- Default Value:
- Flags:
The peer’s TLS certificate
- Soup.Socket.props.tls_errors¶
- Name:
tls-errors
- Type:
- Default Value:
- Flags:
Errors with the peer’s TLS certificate
- Soup.Socket.props.trusted_certificate¶
-
Whether the server certificate is trusted, if this is an SSL socket
- Soup.Socket.props.use_thread_context¶
- Name:
use-thread-context
- Type:
- Default Value:
- Flags:
Use
GLib.MainContext.get_thread_default
().New in version 2.38.