## InfSimulatedConnection

InfSimulatedConnection — Simulated network connection

## Stability Level

Unstable, unless otherwise indicated

## Functions

InfSimulatedConnection * | inf_simulated_connection_new ()
InfSimulatedConnection * | inf_simulated_connection_new_with_io ()
void | inf_simulated_connection_connect ()
void | inf_simulated_connection_set_mode ()
void | inf_simulated_connection_flush ()

## Properties

InfIo * | io | Read / Write / Construct Only
InfSimulatedConnectionMode | mode | Read / Write / Construct
InfSimulatedConnection * | target | Read / Write

## Types and Values

struct | InfSimulatedConnection
struct | InfSimulatedConnectionClass
enum | InfSimulatedConnectionMode

## Object Hierarchy

        GEnum
        ╰── InfSimulatedConnectionMode
        GObject
        ╰── InfSimulatedConnection

## Implemented Interfaces

InfSimulatedConnection implements InfXmlConnection.

## Includes

    #include <libinfinity/common/inf-simulated-connection.h>

## Description

InfSimulatedConnection simulates a connection and can be used everywhere where a InfXmlConnection is expected. Use `inf_simulated_connection_connect()` to connect two such connections so that data sent through one is received by the other.

## Functions

### inf_simulated_connection_new ()

    InfSimulatedConnection *
    inf_simulated_connection_new (void);

Creates a new InfSimulatedConnection. A connection created this way cannot be switched to `INF_SIMULATED_CONNECTION_IO_CONTROLLED` mode. Use `inf_simulated_connection_new_with_io()` instead if you intend to do that.

[constructor]

#### Returns

A new InfSimulatedConnection.

[transfer full]

### inf_simulated_connection_new_with_io ()

    InfSimulatedConnection *
    inf_simulated_connection_new_with_io (InfIo *io);

Creates a new InfSimulatedConnection with the given InfIo. This connection can be used with `INF_SIMULATED_CONNECTION_IO_CONTROLLED` mode. If you don't intend to use that mode then using `inf_simulated_connection_new()` is also good enough since the InfIo object is not required in that case.

[constructor]

#### Parameters

io | The main loop to be used for `INF_SIMULATED_CONNECTION_IO_CONTROLLED` mode. |

#### Returns

A new InfSimulatedConnection.

[transfer full]

### inf_simulated_connection_connect ()

    void
    inf_simulated_connection_connect (InfSimulatedConnection *connection,
                                      InfSimulatedConnection *to);

Connects two simulated connections, so that data sent through one of them is received by the other one and vice versa. So one call to this function connects both InfSimulatedConnections to each other. There is no need to call this function once for each connection.

If one or both of the connections already have another target, then the simulated connection between those is closed first.

#### Parameters

connection | A InfSimulatedConnection. |
to | The target connection. |

### inf_simulated_connection_set_mode ()

    void
    inf_simulated_connection_set_mode (InfSimulatedConnection *connection,
                                       InfSimulatedConnectionMode mode);

Sets the mode of the simulated connection.

In `INF_SIMULATED_CONNECTION_IMMEDIATE` mode, messages sent through the connection are received by the target during the call to `inf_xml_connection_send()`.

In `INF_SIMULATED_CONNECTION_DELAYED` mode, messages sent are queued and received by the target when `inf_simulated_connection_flush()` is called.

In `INF_SIMULATED_CONNECTION_IO_CONTROLLED` mode, messages are queued and received by the target as soon as a dispatch handler (see `inf_io_add_dispatch()`) installed on the main loop is called.

When changing the mode from `INF_SIMULATED_CONNECTION_DELAYED` or `INF_SIMULATED_CONNECTION_IO_CONTROLLED` to `INF_SIMULATED_CONNECTION_IMMEDIATE`, then the queue is flushed, too.

#### Parameters

connection | A InfSimulatedConnection. |
mode | The new mode to set. |

### inf_simulated_connection_flush ()

    void
    inf_simulated_connection_flush (InfSimulatedConnection *connection);

When `connection` 's mode is `INF_SIMULATED_CONNECTION_DELAYED` or `INF_SIMULATED_CONNECTION_IO_CONTROLLED`, then calling this function makes the target connection receive all the queued messages.

#### Parameters

connection | A InfSimulatedConnection. |

## Types and Values

### struct InfSimulatedConnection

    struct InfSimulatedConnection;

InfSimulatedConnection is an opaque data type. You should only access it via the public API functions.

### struct InfSimulatedConnectionClass

    struct InfSimulatedConnectionClass {
    };

This structure does not contain any public fields.

### enum InfSimulatedConnectionMode

The mode of a simulated connection defines when sent messages arrive at the target connection.

#### Members

INF_SIMULATED_CONNECTION_IMMEDIATE | Messages are received directly by the target site when calling `inf_xml_connection_send()`. |
INF_SIMULATED_CONNECTION_DELAYED | Messages are queued, and delivered to the target site when `inf_simulated_connection_flush()` is called. |
INF_SIMULATED_CONNECTION_IO_CONTROLLED | Messages are queued and delivered once the application main loop regains control. This requires the simulated connection to have been created with `inf_simulated_connection_new_with_io()`. |

## Property Details

### The `“io”` property

      “io”                       InfIo *

The main loop to be used for IO_CONTROLLED mode.

Owner: InfSimulatedConnection

Flags: Read / Write / Construct Only

### The `“mode”` property

      “mode”                     InfSimulatedConnectionMode

The mode of the simulated connection.

Owner: InfSimulatedConnection

Flags: Read / Write / Construct

Default value: INF_SIMULATED_CONNECTION_IMMEDIATE

### The `“target”` property

      “target”                   InfSimulatedConnection *

The simulated connection receiving data sent through this connection.

Owner: InfSimulatedConnection

Flags: Read / Write