Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

socket.c File Reference

Implementation of internal macs socket functionality. Unless you're interested in macs' internal workings, you're probably looking for libmacs.h. More...

#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <rpc/types.h>
#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
#include "libmacs.h"
#include "common.h"

Functions

_macs_sock_new_macs_sock ()
int _macs_connect (_macs_sock *s)
int _macs_do_write (int S, const void *B, int L)
 Function to do actual socket writing.

int _macs_do_read (_macs_sock *s, char **buf, const char *sen, int len)
int _macs_do_pings (macs_session *sess, int svc)
int _macs_parse_tcp_addr (const char *addr, char **host, long *port)
 Parses address in host:port form.

_macs_sock_macs_append_sock (_macs_ctx *ctx)
 Appends a new _macs_sock to the list in the given _macs_ctx.

int _macs_add_unix_server (_macs_ctx *ctx, const char *addr)
int _macs_add_tcp_server (_macs_ctx *ctx, const char *addr)
int _macs_add_server (_macs_ctx *ctx, const char *addr, const _macs_conn_type type)
int _macs_connect_sock (macs_session *sess, int svc)
 Establishes a connection to the server.

int _macs_free_socks (_macs_sock **s)
_macs_sock_macs_get_sock (macs_session *sess, int svc)
int _macs_do_ping (_macs_sock *s, macs_session *sess, int svc)
char * _macs_new_msgid (_macs_sock *s)
 Create a unique identifier.

int _macs_write (_macs_sock *s, const void *morsel, size_t siz, const char *svc, const char *cmd, const macs_session *sess, const char *meth,...)
int _macs_read (_macs_sock *s, char **reply[], char **morsel)
 Reads a reply.


Variables

const char _macs_socket_c_id [] = "$Id: socket.c,v 1.28 2003/08/06 11:46:22 blake Exp $"


Detailed Description

Implementation of internal macs socket functionality. Unless you're interested in macs' internal workings, you're probably looking for libmacs.h.

Id
socket.c,v 1.28 2003/08/06 11:46:22 blake Exp

Function Documentation

_macs_sock * _new_macs_sock  
 

Returns:
Pointer to a blanked _macs_sock.

int _macs_connect _macs_sock   s
 

Connects to the given _macs_sock.

Parameters:
s The auc_sock pointing at the server to connect to
Returns:
1 on success, 0 on failure

int _macs_do_write int    S,
const void *    B,
int    L
 

Function to do actual socket writing.

Parameters:
S The socket to write to
B The buffer to write
L The size of the buffer in bytes
Returns:
0 on failure, 1 on success

int _macs_do_read _macs_sock   s,
char **    buf,
const char *    sen,
int    len
 

Read from the macs_sock until we reach the sentinel, or until we read a certain number of bytes.

Parameters:
s The macs_sock to read from.
buf A pointer-to-pointer to the read data. On success, this should be free()d by the caller.
sen The sentinel to stop reading at. NULL means no sentinel.
len The number of bytes to read. -1 means no limit.
Returns:
1 on success, 0 on failure or EOF
Todo:
use select() timeout from configs

int _macs_do_pings macs_session   sess,
int    svc
 

Do raw pings to given svcs.

Parameters:
ctxp An opaque _macs_ctx pointer from macs_init.
svc The service(s) to ping. Logical OR of MACS_MUX, MACS_AUS, MACS_RPS and MACS_ATS
Returns:
1 on success, 0 on failure

Todo:
This routine ignores the in_use flag on each socket. It's a symptom of the real problem: this library is not thread-safe.

int _macs_parse_tcp_addr const char *    addr,
char **    host,
long *    port
 

Parses address in host:port form.

Parameters:
addr The address to parse
host Pointer to an unallocated *char to store the host portion. Should be free()d.
port Pointer to a long to store the port portion
Returns:
0 on failure, 1 on success

_macs_sock* _macs_append_sock _macs_ctx   ctx
 

Appends a new _macs_sock to the list in the given _macs_ctx.

Parameters:
ctx The _macs_ctx to work with
Returns:
NULL on failure, or a pointer to the newly appended _macs_sock

int _macs_add_unix_server _macs_ctx   ctx,
const char *    addr
 

Add a unix-socket entry to the _macs_sock list in the given _macs_ctx

Parameters:
ctx A _macs_ctx pointer from macs_init.
addr The path to add. If not an absolute path, relative from MACS_VAR_PATH (the config.h constant, possibly overriden by the environement variable of the same name)
Returns:
0 on failure, 1 on success

int _macs_add_tcp_server _macs_ctx   ctx,
const char *    addr
 

Add a tcp-socket entry to the _macs_sock list in the given _macs_ctx

Parameters:
ctx A _macs_ctx pointer from macs_init.
addr The address to add, in host:port form. Not used or free()d
Returns:
0 on failure, 1 on success

int _macs_add_server _macs_ctx   ctx,
const char *    addr,
const _macs_conn_type    type
 

Adds a server to the context.

Parameters:
ctx A _macs_ctx pointer from macs_init.
addr The address to add. If type is MACS_TCP, in host:port form; if type is MACS_UNIX, then a path, absolute or relative to MACS_HOME.
type The type of connection to make. One of MACS_TCP or MACS_UNIX

int _macs_connect_sock macs_session   sess,
int    svc
 

Establishes a connection to the server.

Parameters:
sess The macs_session to work with.
svc Services that need to be available for connection to be considered successful. Logical ORing of MACS_ATS, MACS_AUS and MACS_RPS.
Returns:
1 on success, 0 on failure

int _macs_free_socks _macs_sock **    ctx
 

Releases memory associated with the sockets.

Parameters:
ctx An opaque pointer-to-pointer of _macs_sock
Returns:
1 on success, 0 on failure

_macs_sock* _macs_get_sock macs_session   sess,
int    svc
 

Finds a connected _macs_sock from the given list, or connects one.

Parameters:
ctx A _macs_ctx pointer.
svc The server-type of the socket to return. One of MACS_AUS, MACS_ATS, or MACS_UPS
Returns:
The connected _macs_sock, or NULL on failure

int _macs_do_ping _macs_sock   s,
macs_session   sess,
int    server
 

Pings a server to test for connectivity.

Parameters:
s The connected _macs_sock pointing at the server to test
sess The macs_session to work with.
server The type of server to ping. One of MACS_MUX, MACS_AUS, MACS_RPS or MACS_ATS
Returns:
1 on success, 0 on failure

char* _macs_new_msgid _macs_sock   s
 

Create a unique identifier.

Parameters:
s The _macs_sock to which the msg will be written with the id we create.
Returns:
A string identifier. Should be free()d
From the protocol spec: A case-sensitive unique request identifier consisting of a string of characters from ASCII values 33 through 126 decimal, or all the printable characters on a standard qwerty keyboard. NO WHITE SPACE!

int _macs_write _macs_sock   s,
const void *    morsel,
size_t    siz,
const char *    svc,
const char *    cmd,
const macs_session   sess,
const char *    meth,
...   
 

Write to the _macs_sock

Parameters:
s The _macs_sock to write to
morsel The data morsel
siz The size of the data morsel in bytes
svc The service to speak to
cmd The command to give the service
sess A MACS session
meth The method to apply to the command.
... A NULL-terminated list of command-specific words to be written consecutively.
Returns:
1 on success, 0 on failure
None of the words (svc, cmd, ...) may have spaces. This is not checked but it will break the protocol. The session information in the sess parameter will be used in the protocol. Absent uid and skey data will be replaced with "0"

int _macs_read _macs_sock   s,
char **    reply[],
char **    morsel
 

Reads a reply.

Parameters:
s The _macs_sock to read from.
reply A pointer to an array of strings. The reply will be stored here.
morsel A pointer-to-pointer to the morsel.
Returns:
1 on success, 0 on failure
Note:
After success, _macs_free_reply(reply,morsel) should be called to free resources.
This routine reads a reply from the given socket, including the data morsel, if any. The reply itself is broken into words and stored as an array of strings.


Variable Documentation

const char _macs_socket_c_id[] = "$Id: socket.c,v 1.28 2003/08/06 11:46:22 blake Exp $"
 

For use by ident


Generated on Fri Aug 8 09:53:44 2003 for MACS Client C API by doxygen1.3-rc3