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