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 <malloc.h>
#include <netinet/in.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_sock (_macs_sock *type, int server)
 Goes through the linked list of servers and connects one.

int _macs_connect (_macs_sock *s)
int _macs_free_socklist (_macs_sock **s)
 Free all the sockets in this linked list.

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_add_server (_macs_ctx *ctx, const char *addr, int stype)
int _macs_connect_socks (_macs_ctx *ctx, int servers)
int _macs_free_socks (_macs_ctx *ctx, int servers)
_macs_sock_macs_get_sock (const _macs_ctx *ctx, int server)
int macs_ping (const void *ctxp, int servers)
 Ping servers.

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


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.10 2002/07/27 02:12:41 santana Exp


Function Documentation

_macs_sock * _new_macs_sock  
 

Returns:
Pointer to a blanked _macs_sock.

int _macs_connect_sock _macs_sock   type,
int    server
 

Goes through the linked list of servers and connects one.

Parameters:
type  The linked list to work with.
server  The server-type of the sockets in this list. One of MACS_AUS, MACS_UPS or MACS_ATS
Returns:
1 on success, 0 on failure

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_free_socklist _macs_sock **    s
 

Free all the sockets in this linked list.

Parameters:
s  The linked list to work with.
Returns:
1 on success

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

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
Todo:
use select() timeout from configs

int _macs_add_server _macs_ctx   ctx,
const char *    addr,
int    stype
 

Adds a server to the context.

Parameters:
ctx  A _macs_ctx pointer from macs_init.
addr  The address to add, in host:port form
stype  The type of server to add. One of MACS_AUS, MACS_UPS, or MACS_ATS

int _macs_connect_socks _macs_ctx   ctx,
int    servers
 

Find good, working servers and brings up connections to them.

Parameters:
ctx  A _macs_ctx pointer from macs_init.
servers  The types of servers to connect to. An ORing of MACS_AUS, MACS_ATS, MACS_UPS, and MACS_ALL
Returns:
1 on success, 0 on failure

int _macs_free_socks _macs_ctx   ctx,
int    servers
 

Releases memory associated with the sockets.

Parameters:
ctx  An opaque _macs_ctx pointer from macs_init.
servers  The types of servers to connect to. An ORing of MACS_AUS, MACS_ATS, MACS_UPS, and MACS_ALL
Returns:
1 on success, 0 on failure

_macs_sock* _macs_get_sock const _macs_ctx   ctx,
int    server
 

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

Parameters:
ctx  A _macs_ctx pointer.
server  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,
int    server
 

Pings a server to test for connectivity.

Parameters:
s  The connected _macs_sock pointing at the server to test
server  The type of server to ping. One of MACS_AUS, MACS_UPS or MACS_ATS
Returns:
1 on success, 0 on failure

int _macs_write _macs_sock   s,
const void *    morsel,
size_t    siz,
const char *    svc,
const char *    cmd,
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
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.

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.


Generated on Tue Oct 8 22:15:53 2002 for MACS Client C API by doxygen1.2.16