annotate PsiCLASS-1.0.2/samtools-0.1.19/knetfile.h @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #ifndef KNETFILE_H
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #define KNETFILE_H
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include <stdint.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5 #include <fcntl.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 #ifndef _WIN32
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 #define netread(fd, ptr, len) read(fd, ptr, len)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 #define netwrite(fd, ptr, len) write(fd, ptr, len)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 #define netclose(fd) close(fd)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 #else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 #include <winsock2.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 #define netread(fd, ptr, len) recv(fd, ptr, len, 0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 #define netwrite(fd, ptr, len) send(fd, ptr, len, 0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 #define netclose(fd) closesocket(fd)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 // FIXME: currently I/O is unbuffered
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 #define KNF_TYPE_LOCAL 1
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 #define KNF_TYPE_FTP 2
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 #define KNF_TYPE_HTTP 3
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 typedef struct knetFile_s {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 int type, fd;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 int64_t offset;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 char *host, *port;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 // the following are for FTP only
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 int ctrl_fd, pasv_ip[4], pasv_port, max_response, no_reconnect, is_ready;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 char *response, *retr, *size_cmd;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 int64_t seek_offset; // for lazy seek
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 int64_t file_size;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 // the following are for HTTP only
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 char *path, *http_host;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 } knetFile;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 #define knet_tell(fp) ((fp)->offset)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 #define knet_fileno(fp) ((fp)->fd)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 #ifdef __cplusplus
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 extern "C" {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 #ifdef _WIN32
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 int knet_win32_init();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 void knet_win32_destroy();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 knetFile *knet_open(const char *fn, const char *mode);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 This only works with local files.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 knetFile *knet_dopen(int fd, const char *mode);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 If ->is_ready==0, this routine updates ->fd; otherwise, it simply
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 reads from ->fd.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 off_t knet_read(knetFile *fp, void *buf, off_t len);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 /*
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 This routine only sets ->offset and ->is_ready=0. It does not
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 communicate with the FTP server.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 off_t knet_seek(knetFile *fp, int64_t off, int whence);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 int knet_close(knetFile *fp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 #ifdef __cplusplus
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 #endif
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 #endif