Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
/*
netFileCopyer
Copyright (C) 2004 Dmitry S. Vasilchenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
system and in the file COPYING in the Linux kernel source.
*/
#ifndef _OS_SPEC_H
#define _OS_SPEC_H
#include <qstring.h>
ssize_t get_fsize(const char *fname);
#define OI_DATA 45
#define OI_ACK 50
#define OI_HELLO 100
#define OI_ABS 63
#define OI_TIMEWAIT 30
#define OI_RETR_TOUT 0.2
#define OI_READ_TOUT 30
#define TSCALE 1000
#define OI_BLOCK 12
#define OI_NONBLOCK 22
#define OI_MAXBUFFER 40000 /* maximum receive buffer length */
#define OI_MAXWAITING 10000
struct oi_hdr{
unsigned char flag; /* flags */
unsigned long number; /* unique packet number */
};
struct oi_packet{
unsigned char flag; /* flags */
unsigned long number; /* unique packet number */
char *buffer; /* message buffer... */
size_t len; /* ... and its length */
unsigned long t_time; /* send or receive time */
unsigned long t_retry; /* last re-transfer time */
};
class oi_queue{
public:
void out_handler();
void in_handler();
int sd;
private:
/* out packets */
struct oi_packet **out_queue;
int out_len; /* actual length */
int out_size; /* allocated size */
void out_remove(int index);
// int out_index(unsigned long number);
// void out_mark_abs(unsigned long number);
unsigned long w_last;
int in_buffer[2]; /* pipe descriptor */
size_t in_len;
char in_dgbuffer[OI_MAXBUFFER];
char *pack(struct oi_packet *pp, size_t *str_size);
struct oi_packet *unpack(char *str, size_t str_len);
time_t init_time;
unsigned long get_time();
unsigned int counter; /* incremental packet number counter */
int conn;
int stop;
pid_t oi_pid;
public:
sigset_t block_mask;
sigset_t old_mask;
sigset_t zero_mask;
oi_queue(int p_sd, int p_conn);
~oi_queue();
void q_stop();
int out(char *buf, size_t len);
int in(char *buf, size_t len);
};
class oi_connect{
public:
oi_connect(); /* create socket */
~oi_connect();
int d_connect(const char *p_ip, unsigned int p_port);
int d_accept(unsigned int p_port);
void d_disconnect();
int d_send(const void *buf, size_t len);
int d_recv(void *buf, size_t len);
void d_stop();
QString get_last_error();
int estate();
private:
int stop;
/* error handling */
QString err_str;
int err_state;
void hold_error(const char *);
unsigned int port;
char *ip;
/* send queue */
oi_queue *q;
};
typedef struct sockaddr SA;
struct oi_context{
pid_t pid;
class oi_queue *c_cl;
};
#endif
Соседние файлы в папке net_copy