# mco_HA_attach_replica

This function is called by the master application (primary master process for shared memory application) to wait for a connection request from a replica.

### For an overview see page HA Applications

### Prototype

        mco_HA_attach_replica(	mco_db_h db,
                     char* masterport,
                     timer_unit timeout );

### Arguments

db | Database connection handle
masterport | Transport layer dependent address of master. For example, port number for TCP and UDP (eg."10000"), or pipe name for pipes (eg. "/tmp/test00").
timeout | Connection timeout period. If no replicas connect within this period, the function returns `MCO_E_NW_TIMEOUT`.

### Description

This function is called by the master application (primary master process for shared memory application) to wait for a connection request from a replica. Upon receiving a connection request, it sets up a communication channel and performs initial replica synchronization if needed. Usually this function is called in a separate thread.

(Please note that ``mco_HA_keep_alive`` and the `mco_HA_attach_replica()` threads need to have their own separate database connections.)

### Return Codes

MCO_S_OK | The replica was connected successfully
MCO_E_HA_PROTOCOLERR | Incompatible protocol
MCO_E_HA_IOERROR | The master was unable to send or receive a message to/from the replica.
MCO_E_NW_KILLED_BY_REPLICA | The replica has completed initial synchronization and has sent the `KILL_MASTER` message to the master . (See function mco_HA_replica_params_init() flag `MCO_HAMODE_FORCE_MASTER`)
MCO_E_NW_TIMEOUT | No replicas connected within the specified timeout period.
other MCO_E_NW_* codes | Errors in the network transport layer.