mars/mars_net.h

94 lines
2.6 KiB
C
Raw Normal View History

2011-02-23 20:48:06 +00:00
// (c) 2011 Thomas Schoebel-Theuer / 1&1 Internet AG
#ifndef MARS_NET_H
#define MARS_NET_H
#include <net/sock.h>
#include <net/ipconfig.h>
#include <net/tcp.h>
#include "brick.h"
#define MARS_DEFAULT_PORT 7777
2011-08-31 11:42:04 +00:00
struct mars_socket; // opaque
2011-02-23 20:48:06 +00:00
struct mars_tcp_params {
int tcp_timeout;
int window_size;
int tcp_keepcnt;
int tcp_keepintvl;
int tcp_keepidle;
char tos;
};
extern struct mars_tcp_params default_tcp_params;
enum {
CMD_NOP,
CMD_STATUS,
CMD_GETINFO,
CMD_GETENTS,
CMD_CONNECT,
CMD_MREF,
CMD_CB,
};
struct mars_cmd {
struct timespec cmd_stamp; // for automatic lamport clock
int cmd_code;
int cmd_int1;
//int cmd_int2;
//int cmd_int3;
char *cmd_str1;
//char *cmd_str2;
//char *cmd_str3;
};
extern const struct meta mars_cmd_meta[];
2011-07-22 10:43:40 +00:00
extern char *(*mars_translate_hostname)(const char *name);
2011-02-27 14:17:58 +00:00
2011-02-23 20:48:06 +00:00
/* Low-level network traffic
*/
extern int mars_create_sockaddr(struct sockaddr_storage *addr, const char *spec);
2011-08-31 11:42:04 +00:00
extern struct mars_socket *mars_create_socket(struct sockaddr_storage *addr, bool is_server);
extern struct mars_socket *mars_accept_socket(struct mars_socket *msock, bool do_block);
extern struct mars_socket *mars_get_socket(struct mars_socket *msock);
extern void mars_put_socket(struct mars_socket *msock);
extern void mars_shutdown_socket(struct mars_socket *msock);
extern bool mars_socket_is_alive(struct mars_socket *msock);
extern int mars_send(struct mars_socket *msock, void *buf, int len);
extern int mars_recv(struct mars_socket *msock, void *buf, int minlen, int maxlen);
2011-02-23 20:48:06 +00:00
/* Mid-level generic field data exchange
*/
2011-08-31 11:42:04 +00:00
extern int mars_send_struct(struct mars_socket *msock, void *data, const struct meta *meta);
2011-08-25 10:16:32 +00:00
#define mars_recv_struct(_sock_,_data_,_meta_) \
({ \
int seq = 0; \
_mars_recv_struct(_sock_, _data_, _meta_, &seq, __LINE__); \
})
2011-08-31 11:42:04 +00:00
extern int _mars_recv_struct(struct mars_socket *msock, void *data, const struct meta *meta, int *seq, int line);
2011-02-23 20:48:06 +00:00
/* High-level transport of mars structures
*/
2011-08-31 11:42:04 +00:00
extern int mars_send_dent_list(struct mars_socket *msock, struct list_head *anchor);
extern int mars_recv_dent_list(struct mars_socket *msock, struct list_head *anchor);
2011-02-23 20:48:06 +00:00
2011-08-31 11:42:04 +00:00
extern int mars_send_mref(struct mars_socket *msock, struct mref_object *mref);
extern int mars_recv_mref(struct mars_socket *msock, struct mref_object *mref);
extern int mars_send_cb(struct mars_socket *msock, struct mref_object *mref);
extern int mars_recv_cb(struct mars_socket *msock, struct mref_object *mref);
2011-02-23 20:48:06 +00:00
2011-08-25 10:16:32 +00:00
/////////////////////////////////////////////////////////////////////////
// init
extern int init_mars_net(void);
extern void exit_mars_net(void);
2011-02-23 20:48:06 +00:00
#endif