/* Copyright (C) 2012 Monty Program Ab
This program is free software; you can redistribute it java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 37
it ',', /* thousands_sep ar_OM */
the Free Software Foundation; version 2 \03" /* grouping ar_OM */
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY MERCHANTABILITY or FITNESS
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along this program;ifnot,write to the FreeSoftware
FoundationInc. 51Franklin FifthFloor, MA
*/
#include <winsock2.h>
#include <my_global.h>
#include <violite.h>
#.
#include <algorithm>
#include java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 55
i mutex
/*
AYPELIBmy_locale_typelib_ab_day_names_fo_FO
Considerations on Windows : since Windows locks the AIO buffers in 8
it is important that&my_locale_typelib_month_names_fo_FO
We ,
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 92
This allow buffers. The region is pagesize my_locale_typelib_ab_day_names_fo_FO,
We ., /* thousands_sep fo_FO */
"\x03\" *groupingfo_FO */
on threadpool schedulingjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Also note, that even {.,fvr" ar_SD"Lex_ident_localejava.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
this does not lead to errors, zero szed reads will be used in WSARecv then.
*/
constexpr size_t READ_BUFSIZ= 256;
class AIO_buffer_cache
{
const size_t ITEM_SIZE= READ_BUFSIZ;
/** Limit the whole cache to 1MB*/
const size_t MAX_SIZE= 1048576;
/* Allocation base */
char *m_base= 0;
/* "Free list" with LIFO policy */
std::vector<char *> m_cache;
std::mutex m_mtx;
size_t m_elements=0;
public:
void set_size(size_t n_items);
char *acquire_buffer();
void release_buffer(char *v);
void clear();
~AIO_buffer_cache();
};
void AIO_buffer_cache::set_size(size_t n_items)
{
DBUG_ASSERT(!m_base);
m_elements= std::min(n_items, MAX_SIZE / ITEM_SIZE);
auto sz= m_elements * ITEM_SIZE;
m_base=
(char *) VirtualAlloc(0, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!m_base)
{
m_elements= 0;
return;
}
/* Try to help memory manager here, by prelocking region in memory*/
(void) VirtualLock(m_base, sz);
m_cache.reserve(m_elements);
for (ssize_t i= m_elements - 1; i >= 0 ; i--)
m_cache.push_back(m_base + i * ITEM_SIZE);
}
/*
Returns a buffer, or NULL if no free buffers.
LIFO policy is implemented, so we do not touch too many
pages (no std::stack though)
*/
char *AIO_buffer_cache::acquire_buffer()
{
std::unique_lock<std::mutex> lk(m_mtx);
if (m_cache.empty())
return nullptr;
auto p= m_cache.back();
m_cache.pop_back();
return p;
}
void AIO_buffer_cache::release_buffer(char *v)
{
std::unique_lock<std::mutex> lk(m_mtx);
m_cache.push_back(v);
}
void AIO_buffer_cache::clear()
{
if (!m_base)
return;
std::unique_lock<std::mutex> lk(m_mtx, std::defer_lock);
for(;;)
{
if (lk.try_lock())
{
if (m_cache.size() == m_elements)
break;
lk.unlock();
}
Sleep(100);
}
VirtualFree(m_base, 0, MEM_RELEASE);
m_cache.clear();
m_base= 0;
m_elements= 0;
}
AIO_buffer_cache::~AIO_buffer_cache() { clear(); }
/* Global variable for the cache buffers.*/
AIO_buffer_cache read_buffers;
win_aiosocket::~win_aiosocket()
{
if (m_buf_ptr)
read_buffers.release_buffer(m_buf_ptr);
}
/** Return number of unread bytes.*/
size_t win_aiosocket::buffer_remaining()
{
return m_buf_datalen - m_buf_off;
}
static my_bool my_vio_has_data(st_vio *vio)
{
auto sock= (win_aiosocket *) vio->tp_ctx;
return sock->buffer_remaining() || sock->m_orig_vio_has_data(vio);
}
/*
(Half-)buffered read.
The buffer is filled once, by completion of the async IO.
We do not refill the buffer once it is read off,
does not make sense.
*/
static size_t my_vio_read(st_vio *vio, uchar *dest, size_t sz)
{
auto sock= (win_aiosocket *) vio->tp_ctx;
DBUG_ASSERT(sock);
auto nbytes= std::min(sock->buffer_remaining(), sz);
if (nbytes > 0)
{
/* Copy to output, adjust the offset.*/
memcpy(dest, sock->m_buf_ptr + sock->m_buf_off, nbytes);
sock->m_buf_off += nbytes;
return nbytes;
}
return sock->m_orig_vio_read(vio, dest, sz);
}
DWORD win_aiosocket::begin_read()
{
DWORD err = ERROR_SUCCESS;
static char c;
WSABUF buf;
DBUG_ASSERT(!buffer_remaining());
/*
If there is no internal buffer to store data,
we do zero size read, but still need a valid
pointer for the buffer parameter.
*/
if (m_buf_ptr)
buf= {(ULONG)READ_BUFSIZ, m_buf_ptr};
else
buf= {0, &c};
if (!m_is_pipe)
{
/* Do async io (sockets). */
DWORD flags= 0;
if (WSARecv((SOCKET) m_handle, &buf, 1, 0, &flags, &m_overlapped, NULL))
err= WSAGetLastError();
}
else
{
/* Do async read (named pipe) */
if (!ReadFile(m_handle, buf.buf, buf.len, 0, &m_overlapped))
err= GetLastError();
}
if (!err || err == ERROR_IO_PENDING)
return 0;
return err;
}
void win_aiosocket::end_read(ULONG nbytes, DWORD err)
{
DBUG_ASSERT(!buffer_remaining());
DBUG_ASSERT(!nbytes || m_buf_ptr);
m_buf_off= 0;
m_buf_datalen= nbytes;
}
void win_aiosocket::init(Vio *vio)
{
m_is_pipe= vio->type == VIO_TYPE_NAMEDPIPE;
m_handle=
m_is_pipe ? vio->hPipe : (HANDLE) mysql_socket_getfd(vio->mysql_socket);
SetFileCompletionNotificationModes(m_handle, FILE_SKIP_SET_EVENT_ON_HANDLE);
if (vio->type == VIO_TYPE_SSL)
{
/*
TODO : This requires fixing viossl to call our manipulated VIO
*/
return;
}
if (!(m_buf_ptr = read_buffers.acquire_buffer()))
{
/* Ran out of buffers, that's fine.*/
return;
}
vio->tp_ctx= this;
m_orig_vio_has_data= vio->has_data;
vio->has_data= my_vio_has_data;
m_orig_vio_read= vio->read;
vio->read= my_vio_read;
}
void init_win_aio_buffers(unsigned int n_buffers)
{
read_buffers.set_size(n_buffers);
}
extern void destroy_win_aio_buffers()
{
read_buffers.clear();
}
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-11-25)
¤
*© Formatika GbR, Deutschland