RULI Synchronous SRV API

RULI's synchronous API is a simple layer built on top of the asynchronous interface in order to emulate blocking behavior.

To make a synchronous query, the application just calls a function passing the proper arguments. When the function returns, the query is complete.

The synchronous interface is suitable for multi-threaded applications.


Main Entry Points

ruli_sync_t *ruli_sync_query(const char *txt_service, const char *txt_domain, int fallback_port);
void ruli_sync_delete(ruli_sync_t *syn_qry);

Auxiliary Functions

int ruli_sync_srv_code(ruli_sync_t *syn_qry);
int ruli_sync_rcode(ruli_sync_t *syn_qry);
ruli_list_t *ruli_sync_srv_list(ruli_sync_t *syn_qry);

Types

/* Opaque query context */
typedef struct {
  /* 
   * Only private members
   */
} ruli_sync_t;

Functions


ruli_sync_t *ruli_sync_query(const char *txt_service, const char *txt_domain, int fallback_port);

Submit a synchronous query for the service txt_service under the domain txt_domain. If the query submission fails, a null pointer is returned. A pointer to a ruli_sync_t structure is returned when the query completes.

Input parameters

Example

ruli_sync_t *query;

query = ruli_sync_query("_smtp._tcp", "gnu.org", -1);

void ruli_sync_delete(ruli_sync_t *syn_qry);

Release the resources allocated by ruli_sync_query() under the ruli_sync_t structure. Call ruli_sync_delete() when the answer is no longer needed.


int ruli_sync_srv_code(ruli_sync_t *syn_qry);

This functions returns the answer code of the underlying SRV query. This code indicates whether the query was actually successful (RULI_SRV_CODE_OK).


int ruli_sync_rcode(ruli_sync_t *syn_qry);

If the underlying SRV query completed sucessfully (ruli_sync_srv_code() returned RULI_SRV_CODE_OK), ruli_sync_rcode() can be used to retrieve the RCODE sent by the name server.


ruli_list_t *ruli_sync_srv_list(ruli_sync_t *syn_qry);

This functions provides the list of SRV records when both SRV answer code and server RCODE are successful.

Note the SRV records provided in this list are already properly sorted for prompt usage. The whole RFC2782 priority/weight logic is already applied. The application only needs to scan the SRV records and try to use each address in the order they appear.

Sample Program

The tools/syncsolver utility provides an example of usage for the synchronous API.

A syncsolver session:
$ echo _smtp._tcp.vanrein.org | ./syncsolver
_smtp._tcp.vanrein.org target=phantom.vanrein.org. port=25 addresses=:217.120.133.159
_smtp._tcp.vanrein.org target=sitemail.everyone.net. port=25 addresses=:216.200.145.35

$Id: synchronous-srv-api.html,v 1.6 2003/01/17 11:29:28 evertonm Exp $