/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/



#ifndef ___M_STREAM_H___
#define ___M_STREAM_H___

#include	<stdio.h>

typedef struct s_file {
	S_HEADER	h;
	int		fid;
	char *		filename;
} S_FILE;

typedef struct s_accept {
	S_HEADER	h;
	int		fid;
} S_ACCEPT;

typedef struct s_terminal {
	S_HEADER	h;
	union stream *	inp;
	union stream *	out;
	int		(*prompt)();
} S_TERMINAL;


typedef struct pipe_read_buf {
	struct pipe_read_buf *	next;
	int			len;
	int			ptr;
} PIPE_READ_BUF;

typedef struct s_fpipe {
	S_HEADER	h;
	int		fid_read;
	int		fid_write;
	int		read_flag;
	int		this_ip_addr;
	int		peer_ip_addr;
	int		flags;
#define FPF_FLUSH	0x00000001
#define FPF_WRITE	0x00000002
	PIPE_READ_BUF *	head;
	PIPE_READ_BUF * tail;
} S_FPIPE;

#ifdef STREAM_LIB

typedef union stream {
	S_HEADER	h;
	S_FILE		file;
	S_ACCEPT	accept;
	S_TERMINAL	terminal;
	S_STRING	str;
	S_CHAIN		chain;
	S_FPIPE		fpipe;
	S_XLoHTTP	xoh;
} STREAM;

typedef struct proc_send {
	char 		msg[32];
	int		fid[3];
} PROC_SEND;

typedef struct proc_recv {
	char *		ptr;
	int		fidp;
	S_TABLE *	tbl;
} PROC_RECV;

#else

typedef void STREAM;

#endif

extern STREAM ** recv_streams;
extern int recv_streams_len;
extern S_TABLE s_file_table;
extern S_TABLE s_accept_table;
extern S_TABLE s_terminal_table;
extern S_TABLE s_fpipe_table;
#define s_pipe_table s_file_table
#define s_socket_table s_file_table

#endif
