gi-soup-2.4.24: Libsoup bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Soup.Objects.Socket

Description

Socket is libsoup's TCP socket type. While it is primarily intended for internal use, Sockets are exposed in the API in various places, and some of their methods (eg, socketGetRemoteAddress) may be useful to applications.

Synopsis

Exported types

newtype Socket Source #

Memory-managed wrapper type.

Constructors

Socket (ManagedPtr Socket) 

Instances

Instances details
Eq Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

Methods

(==) :: Socket -> Socket -> Bool #

(/=) :: Socket -> Socket -> Bool #

GObject Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

ManagedPtrNewtype Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

Methods

toManagedPtr :: Socket -> ManagedPtr Socket

TypedObject Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

Methods

glibType :: IO GType

HasParentTypes Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

IsGValue (Maybe Socket) Source #

Convert Socket to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Soup.Objects.Socket

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe Socket -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe Socket)

type ParentTypes Socket Source # 
Instance details

Defined in GI.Soup.Objects.Socket

type ParentTypes Socket = '[Object, Initable]

class (GObject o, IsDescendantOf Socket o) => IsSocket o Source #

Type class for types which can be safely cast to Socket, for instance with toSocket.

Instances

Instances details
(GObject o, IsDescendantOf Socket o) => IsSocket o Source # 
Instance details

Defined in GI.Soup.Objects.Socket

toSocket :: (MonadIO m, IsSocket o) => o -> m Socket Source #

Cast to Socket, for types for which this is known to be safe. For general casts, use castTo.

Methods

connectAsync

socketConnectAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: a client Socket (which must not already be connected)

-> Maybe b

cancellable: a Cancellable, or Nothing

-> SocketCallback

callback: callback to call after connecting

-> m () 

Begins asynchronously connecting to sock's remote address. The socket will call callback when it succeeds or fails (but not before returning from this function).

If cancellable is non-Nothing, it can be used to cancel the connection. callback will still be invoked in this case, with a status of StatusCancelled.

connectSync

socketConnectSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: a client Socket (which must not already be connected)

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m Word32

Returns: a success or failure code.

Attempt to synchronously connect sock to its remote address.

If cancellable is non-Nothing, it can be used to cancel the connection, in which case socketConnectSync will return StatusCancelled.

disconnect

socketDisconnect Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m () 

Disconnects sock. Any further read or write attempts on it will fail.

getFd

socketGetFd Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Int32

Returns: sock's file descriptor.

Gets sock's underlying file descriptor.

Note that fiddling with the file descriptor may break the Socket.

getLocalAddress

socketGetLocalAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Address

Returns: the Address

Returns the Address corresponding to the local end of sock.

Calling this method on an unconnected socket is considered to be an error, and produces undefined results.

getRemoteAddress

socketGetRemoteAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Address

Returns: the Address

Returns the Address corresponding to the remote end of sock.

Calling this method on an unconnected socket is considered to be an error, and produces undefined results.

isConnected

socketIsConnected Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Bool

Returns: True or False.

Tests if sock is connected to another host

isSsl

socketIsSsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Bool

Returns: True if sock has SSL credentials set

Tests if sock is doing (or has attempted to do) SSL.

listen

socketListen Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a server Socket (which must not already be connected or listening)

-> m Bool

Returns: whether or not sock is now listening.

Makes sock start listening on its local address. When connections come in, sock will emit Socket::new_connection.

read

socketRead Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: buffer to read into

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: a SocketIOStatus, as described above (or SocketIOStatusEof if the socket is no longer connected, or SocketIOStatusError on any other error, in which case error will also be set). (Can throw GError)

Attempts to read up to len bytes from sock into buffer. If some data is successfully read, socketRead will return SocketIOStatusOk, and *nread will contain the number of bytes actually read (which may be less than len).

If sock is non-blocking, and no data is available, the return value will be SocketIOStatusWouldBlock. In this case, the caller can connect to the readable signal to know when there is more data to read. (NB: You MUST read all available data off the socket first. readable is only emitted after socketRead returns SocketIOStatusWouldBlock, and it is only emitted once. See the documentation for Socket:non-blocking.)

readUntil

socketReadUntil Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: buffer to read into

-> Ptr ()

boundary: boundary to read until

-> Word64

boundaryLen: length of boundary in bytes

-> Bool

gotBoundary: on return, whether or not the data in buffer ends with the boundary string

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: as for socketRead (Can throw GError)

Like socketRead, but reads no further than the first occurrence of boundary. (If the boundary is found, it will be included in the returned data, and *gotBoundary will be set to True.) Any data after the boundary will returned in future reads.

socketReadUntil 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 <literal>(boundary_len - 1)</literal> 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 boundaryLen if you want to make any progress at all.

startProxySsl

socketStartProxySsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> Text

sslHost: hostname of the SSL server

-> Maybe b

cancellable: a Cancellable

-> m Bool

Returns: success or failure

Starts using SSL on socket, expecting to find a host named sslHost.

startSsl

socketStartSsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> Maybe b

cancellable: a Cancellable

-> m Bool

Returns: success or failure

Starts using SSL on socket.

write

socketWrite Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: data to write

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: a SocketIOStatus, as described above (or SocketIOStatusEof or SocketIOStatusError. error will be set if the return value is SocketIOStatusError.) (Can throw GError)

Attempts to write len bytes from buffer to sock. If some data is successfully written, the return status will be SocketIOStatusOk, and *nwrote will contain the number of bytes actually written (which may be less than len).

If sock is non-blocking, and no data could be written right away, the return value will be SocketIOStatusWouldBlock. In this case, the caller can connect to the writable signal to know when more data can be written. (NB: writable is only emitted after socketWrite returns SocketIOStatusWouldBlock, and it is only emitted once. See the documentation for Socket:non-blocking.)

Properties

asyncContext

No description available in the introspection data.

constructSocketAsyncContext :: (IsSocket o, MonadIO m) => Ptr () -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “async-context” property. This is rarely needed directly, but it is used by new.

getSocketAsyncContext :: (MonadIO m, IsSocket o) => o -> m (Ptr ()) Source #

Get the value of the “async-context” property. When overloading is enabled, this is equivalent to

get socket #asyncContext

fd

No description available in the introspection data.

constructSocketFd :: (IsSocket o, MonadIO m) => Int32 -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “fd” property. This is rarely needed directly, but it is used by new.

getSocketFd :: (MonadIO m, IsSocket o) => o -> m Int32 Source #

Get the value of the “fd” property. When overloading is enabled, this is equivalent to

get socket #fd

gsocket

No description available in the introspection data.

constructSocketGsocket :: (IsSocket o, MonadIO m, IsSocket a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “gsocket” property. This is rarely needed directly, but it is used by new.

iostream

No description available in the introspection data.

constructSocketIostream :: (IsSocket o, MonadIO m, IsIOStream a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “iostream” property. This is rarely needed directly, but it is used by new.

ipv6Only

No description available in the introspection data.

constructSocketIpv6Only :: (IsSocket o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “ipv6-only” property. This is rarely needed directly, but it is used by new.

getSocketIpv6Only :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “ipv6-only” property. When overloading is enabled, this is equivalent to

get socket #ipv6Only

setSocketIpv6Only :: (MonadIO m, IsSocket o) => o -> Bool -> m () Source #

Set the value of the “ipv6-only” property. When overloading is enabled, this is equivalent to

set socket [ #ipv6Only := value ]

isServer

Whether or not the socket is a server socket.

Note that for "ordinary" SoupSockets this will be set for both listening sockets and the sockets emitted by newConnection, but for sockets created by setting Socket:fd, it will only be set for listening sockets.

getSocketIsServer :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “is-server” property. When overloading is enabled, this is equivalent to

get socket #isServer

localAddress

No description available in the introspection data.

constructSocketLocalAddress :: (IsSocket o, MonadIO m, IsAddress a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “local-address” property. This is rarely needed directly, but it is used by new.

getSocketLocalAddress :: (MonadIO m, IsSocket o) => o -> m Address Source #

Get the value of the “local-address” property. When overloading is enabled, this is equivalent to

get socket #localAddress

nonBlocking

Whether or not the socket uses non-blocking I/O.

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 a Socket, the "correct" way to do it is to call socketRead or socketReadUntil repeatedly until you have read everything you want. If it returns SocketIOStatusWouldBlock at any point, stop reading and wait for it to emit the readable signal. Then go back to the reading-as-much-as-you-can loop. Likewise, for writing to a Socket, you should call socketWrite either until you have written everything, or it returns SocketIOStatusWouldBlock (in which case you wait for 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 SocketIOStatusWouldBlock, and so the code that handles that case just won't get used for them.

constructSocketNonBlocking :: (IsSocket o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “non-blocking” property. This is rarely needed directly, but it is used by new.

getSocketNonBlocking :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “non-blocking” property. When overloading is enabled, this is equivalent to

get socket #nonBlocking

setSocketNonBlocking :: (MonadIO m, IsSocket o) => o -> Bool -> m () Source #

Set the value of the “non-blocking” property. When overloading is enabled, this is equivalent to

set socket [ #nonBlocking := value ]

remoteAddress

No description available in the introspection data.

constructSocketRemoteAddress :: (IsSocket o, MonadIO m, IsAddress a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “remote-address” property. This is rarely needed directly, but it is used by new.

getSocketRemoteAddress :: (MonadIO m, IsSocket o) => o -> m Address Source #

Get the value of the “remote-address” property. When overloading is enabled, this is equivalent to

get socket #remoteAddress

sslCreds

No description available in the introspection data.

constructSocketSslCreds :: (IsSocket o, MonadIO m) => Ptr () -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “ssl-creds” property. This is rarely needed directly, but it is used by new.

getSocketSslCreds :: (MonadIO m, IsSocket o) => o -> m (Ptr ()) Source #

Get the value of the “ssl-creds” property. When overloading is enabled, this is equivalent to

get socket #sslCreds

setSocketSslCreds :: (MonadIO m, IsSocket o) => o -> Ptr () -> m () Source #

Set the value of the “ssl-creds” property. When overloading is enabled, this is equivalent to

set socket [ #sslCreds := value ]

sslFallback

No description available in the introspection data.

constructSocketSslFallback :: (IsSocket o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “ssl-fallback” property. This is rarely needed directly, but it is used by new.

getSocketSslFallback :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “ssl-fallback” property. When overloading is enabled, this is equivalent to

get socket #sslFallback

sslStrict

No description available in the introspection data.

constructSocketSslStrict :: (IsSocket o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “ssl-strict” property. This is rarely needed directly, but it is used by new.

getSocketSslStrict :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “ssl-strict” property. When overloading is enabled, this is equivalent to

get socket #sslStrict

timeout

No description available in the introspection data.

constructSocketTimeout :: (IsSocket o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “timeout” property. This is rarely needed directly, but it is used by new.

getSocketTimeout :: (MonadIO m, IsSocket o) => o -> m Word32 Source #

Get the value of the “timeout” property. When overloading is enabled, this is equivalent to

get socket #timeout

setSocketTimeout :: (MonadIO m, IsSocket o) => o -> Word32 -> m () Source #

Set the value of the “timeout” property. When overloading is enabled, this is equivalent to

set socket [ #timeout := value ]

tlsCertificate

No description available in the introspection data.

getSocketTlsCertificate :: (MonadIO m, IsSocket o) => o -> m (Maybe TlsCertificate) Source #

Get the value of the “tls-certificate” property. When overloading is enabled, this is equivalent to

get socket #tlsCertificate

tlsErrors

No description available in the introspection data.

getSocketTlsErrors :: (MonadIO m, IsSocket o) => o -> m [TlsCertificateFlags] Source #

Get the value of the “tls-errors” property. When overloading is enabled, this is equivalent to

get socket #tlsErrors

trustedCertificate

No description available in the introspection data.

getSocketTrustedCertificate :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “trusted-certificate” property. When overloading is enabled, this is equivalent to

get socket #trustedCertificate

useThreadContext

constructSocketUseThreadContext :: (IsSocket o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “use-thread-context” property. This is rarely needed directly, but it is used by new.

getSocketUseThreadContext :: (MonadIO m, IsSocket o) => o -> m Bool Source #

Get the value of the “use-thread-context” property. When overloading is enabled, this is equivalent to

get socket #useThreadContext

Signals

disconnected

type C_SocketDisconnectedCallback = Ptr () -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type SocketDisconnectedCallback = IO () Source #

Emitted when the socket is disconnected, for whatever reason.

afterSocketDisconnected :: (IsSocket a, MonadIO m) => a -> SocketDisconnectedCallback -> m SignalHandlerId Source #

Connect a signal handler for the disconnected signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after socket #disconnected callback

onSocketDisconnected :: (IsSocket a, MonadIO m) => a -> SocketDisconnectedCallback -> m SignalHandlerId Source #

Connect a signal handler for the disconnected signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on socket #disconnected callback

event

type C_SocketEventCallback = Ptr () -> CUInt -> Ptr IOStream -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type SocketEventCallback Source #

Arguments

 = SocketClientEvent

event: the event that occurred

-> IOStream

connection: the current connection state

-> IO () 

Emitted when a network-related event occurs. See event for more details.

Since: 2.38

afterSocketEvent :: (IsSocket a, MonadIO m) => a -> SocketEventCallback -> m SignalHandlerId Source #

Connect a signal handler for the event signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after socket #event callback

genClosure_SocketEvent :: MonadIO m => SocketEventCallback -> m (GClosure C_SocketEventCallback) Source #

Wrap the callback into a GClosure.

mk_SocketEventCallback :: C_SocketEventCallback -> IO (FunPtr C_SocketEventCallback) Source #

Generate a function pointer callable from C code, from a C_SocketEventCallback.

onSocketEvent :: (IsSocket a, MonadIO m) => a -> SocketEventCallback -> m SignalHandlerId Source #

Connect a signal handler for the event signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on socket #event callback

newConnection

type C_SocketNewConnectionCallback = Ptr () -> Ptr Socket -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type SocketNewConnectionCallback Source #

Arguments

 = Socket

new: the new socket

-> IO () 

Emitted when a listening socket (set up with socketListen) 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.

afterSocketNewConnection :: (IsSocket a, MonadIO m) => a -> SocketNewConnectionCallback -> m SignalHandlerId Source #

Connect a signal handler for the newConnection signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after socket #newConnection callback

onSocketNewConnection :: (IsSocket a, MonadIO m) => a -> SocketNewConnectionCallback -> m SignalHandlerId Source #

Connect a signal handler for the newConnection signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on socket #newConnection callback

readable

type C_SocketReadableCallback = Ptr () -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type SocketReadableCallback = IO () Source #

Emitted when an async socket is readable. See socketRead, socketReadUntil and Socket:non-blocking.

afterSocketReadable :: (IsSocket a, MonadIO m) => a -> SocketReadableCallback -> m SignalHandlerId Source #

Connect a signal handler for the readable signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after socket #readable callback

genClosure_SocketReadable :: MonadIO m => SocketReadableCallback -> m (GClosure C_SocketReadableCallback) Source #

Wrap the callback into a GClosure.

onSocketReadable :: (IsSocket a, MonadIO m) => a -> SocketReadableCallback -> m SignalHandlerId Source #

Connect a signal handler for the readable signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on socket #readable callback

writable

type C_SocketWritableCallback = Ptr () -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type SocketWritableCallback = IO () Source #

Emitted when an async socket is writable. See socketWrite and Socket:non-blocking.

afterSocketWritable :: (IsSocket a, MonadIO m) => a -> SocketWritableCallback -> m SignalHandlerId Source #

Connect a signal handler for the writable signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after socket #writable callback

genClosure_SocketWritable :: MonadIO m => SocketWritableCallback -> m (GClosure C_SocketWritableCallback) Source #

Wrap the callback into a GClosure.

onSocketWritable :: (IsSocket a, MonadIO m) => a -> SocketWritableCallback -> m SignalHandlerId Source #

Connect a signal handler for the writable signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on socket #writable callback