]> git.donarmstrong.com Git - samtools.git/blob - knetfile.h
* samtools-0.1.5-4 (r394)
[samtools.git] / knetfile.h
1 #ifndef KNETFILE_H
2 #define KNETFILE_H
3
4 #include <stdint.h>
5 #include <fcntl.h>
6
7 // FIXME: currently I/O is unbuffered
8
9 #define KNF_TYPE_LOCAL 1
10 #define KNF_TYPE_FTP   2
11 #define KNF_TYPE_HTTP  3
12
13 typedef struct knetFile_s {
14         int type, fd;
15         int64_t offset;
16         char *host, *port;
17
18         // the following are for FTP only
19         int ctrl_fd, pasv_ip[4], pasv_port, max_response, no_reconnect, is_ready;
20         char *response, *retr;
21         int64_t seek_offset; // for lazy seek
22
23         // the following are for HTTP only
24         char *path, *http_host;
25 } knetFile;
26
27 #define knet_tell(fp) ((fp)->offset)
28 #define knet_fileno(fp) ((fp)->fd)
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34         knetFile *knet_open(const char *fn, const char *mode);
35
36         /* 
37            This only works with local files.
38          */
39         knetFile *knet_dopen(int fd, const char *mode);
40
41         /*
42           If ->is_ready==0, this routine updates ->fd; otherwise, it simply
43           reads from ->fd.
44          */
45         off_t knet_read(knetFile *fp, void *buf, off_t len);
46
47         /*
48           This routine only sets ->offset and ->is_ready=0. It does not
49           communicate with the FTP server.
50          */
51         int knet_seek(knetFile *fp, off_t off, int whence);
52         int knet_close(knetFile *fp);
53
54 #ifdef __cplusplus
55 }
56 #endif
57
58 #endif