git » nmdb » master » tree

[master] / libnmdb / internal.h.in

#ifndef _INTERNAL_H
#define _INTERNAL_H

/* Different connection types. Used internally to differentiate between the
 * different protocols in struct nmdb_srv. */
#define TIPC_CONN 1
#define TCP_CONN 2
#define UDP_CONN 3
#define SCTP_CONN 4

/* The ID code for requests is hardcoded for now, until asynchronous requests
 * are implemented. */
#define ID_CODE 1

/* For a given buffer, how much into it should the generic library code write
 * the message contents. */
#define TIPC_MSG_OFFSET 0
#define TCP_MSG_OFFSET 4
#define UDP_MSG_OFFSET 0
#define SCTP_MSG_OFFSET 0

/* Defined to 0 or 1 at libnmdb build time according the build configuration,
 * not to be used externally. */
#define ENABLE_TIPC ++CONFIG_ENABLE_TIPC++
#define ENABLE_TCP ++CONFIG_ENABLE_TCP++
#define ENABLE_UDP ++CONFIG_ENABLE_UDP++
#define ENABLE_SCTP ++CONFIG_ENABLE_SCTP++

/* Functions used internally but shared among the different files. */
int compare_servers(const void *s1, const void *s2);
ssize_t srecv(int fd, unsigned char *buf, size_t count, int flags);
ssize_t ssend(int fd, const unsigned char *buf, size_t count, int flags);


/*
 * Server and connection internal types.
 */

#include <sys/types.h>		/* socket defines */
#include <sys/socket.h>		/* socklen_t */

#if ENABLE_TIPC
#include <linux/tipc.h>		/* struct sockaddr_tipc */
#endif

#if (ENABLE_TCP || ENABLE_UDP || ENABLE_SCTP)
#include <netinet/in.h>		/* struct sockaddr_in */
#endif

/* A connection to an nmdb server. */
struct nmdb_srv {
	int fd;
	int type;
	union {

#if ENABLE_TIPC
		struct {
			unsigned int port;
			struct sockaddr_tipc srvsa;
			socklen_t srvlen;
		} tipc;
#endif

#if (ENABLE_TCP || ENABLE_UDP || ENABLE_SCTP)
		struct {
			struct sockaddr_in srvsa;
			socklen_t srvlen;
		} in;
#endif

	} info;
};

/* A connection to one or many nmdb servers. */
struct nmdb_conn {
	unsigned int nservers;
	struct nmdb_srv *servers;
};


#endif