1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
15
16 /**
17 @file
18
19 @details
20 Caching of files with only does (sequential) read or writes of fixed-
21 length records. A read isn't allowed to go over file-length. A read is ok
22 if it ends at file-length and next read can try to read after file-length
23 (and get a EOF-error).
24 Possibly use of asyncronic io.
25 macros for read and writes for faster io.
26 Used instead of FILE when reading or writing whole files.
27 This will make mf_rec_cache obsolete.
28 One can change info->pos_in_file to a higher value to skip bytes in file if
29 also info->read_pos is set to info->read_end.
30 If called through open_cached_file(), then the temporary file will
31 only be created if a write exeeds the file buffer or if one calls
32 flush_io_cache().
33 */
34
35 #include "mariadb.h"
36 #include "sql_priv.h"
37 #include "sql_class.h" // THD
38 #ifdef HAVE_REPLICATION
39
40 extern "C" {
41
42 /**
43 Read buffered from the net.
44
45 @retval
46 1 if can't read requested characters
47 @retval
48 0 if record read
49 */
50
51
_my_b_net_read(IO_CACHE * info,uchar * Buffer,size_t)52 int _my_b_net_read(IO_CACHE *info, uchar *Buffer, size_t)
53 {
54 ulong read_length;
55 NET *net= &(current_thd)->net;
56 DBUG_ENTER("_my_b_net_read");
57
58 if (!info->end_of_file)
59 DBUG_RETURN(1); /* because my_b_get (no _) takes 1 byte at a time */
60 read_length= my_net_read_packet(net, 0);
61 if (unlikely(read_length == packet_error))
62 {
63 info->error= -1;
64 DBUG_RETURN(1);
65 }
66 if (unlikely(read_length == 0))
67 {
68 info->end_of_file= 0; /* End of file from client */
69 DBUG_RETURN(1);
70 }
71 /* to set up stuff for my_b_get (no _) */
72 info->read_end = (info->read_pos = (uchar*) net->read_pos) + read_length;
73 Buffer[0] = info->read_pos[0]; /* length is always 1 */
74
75 /*
76 info->request_pos is used by log_loaded_block() to know the size
77 of the current block.
78 info->pos_in_file is used by log_loaded_block() too.
79 */
80 info->pos_in_file+= read_length;
81 info->request_pos=info->read_pos;
82
83 info->read_pos++;
84
85 DBUG_RETURN(0);
86 }
87
88 } /* extern "C" */
89
90 #elif defined(__WIN__)
91
92 // Remove linker warning 4221 about empty file
93 namespace { char dummy; };
94
95 #endif /* HAVE_REPLICATION */
96
97
98