MySQL 8.0.39
Source Code Documentation
mysql_socket.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25/**
26 @file include/mysql/psi/mysql_socket.h
27*/
28
29#ifndef MYSQL_SOCKET_H
30#define MYSQL_SOCKET_H
31
32#include <errno.h>
33/* For strlen() */
34#include <string.h>
35
36/* HAVE_PSI_*_INTERFACE */
37#include "my_psi_config.h" // IWYU pragma: keep
38
39/* For MY_STAT */
40#include "my_compiler.h"
41#include "my_dir.h"
42#include "my_io.h"
44/* For socket api */
45#ifdef _WIN32
46#include <MSWSock.h>
47#ifdef WIN32_LEAN_AND_MEAN
48#include <winsock2.h>
49#include <ws2def.h>
50#endif
51#define SOCKBUF_T char
52#else
53#include <netinet/in.h>
54
55#define SOCKBUF_T void
56#endif
57
58#include "my_macros.h"
60
61#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
62/* PSI_SOCKET_CALL() as direct call. */
63#include "pfs_socket_provider.h" // IWYU pragma: keep
64#endif
65
66#ifndef PSI_SOCKET_CALL
67#define PSI_SOCKET_CALL(M) psi_socket_service->M
68#endif
69
70/**
71 @defgroup psi_api_socket Socket Instrumentation (API)
72 @ingroup psi_api
73 @{
74*/
75
76/**
77 @def mysql_socket_register(P1, P2, P3)
78 Socket registration.
79*/
80#ifdef HAVE_PSI_SOCKET_INTERFACE
81#define mysql_socket_register(P1, P2, P3) \
82 inline_mysql_socket_register(P1, P2, P3)
83#else
84#define mysql_socket_register(P1, P2, P3) \
85 do { \
86 } while (0)
87#endif
88
89/**
90 Set socket descriptor and address.
91 @param socket instrumented socket
92 @param addr unformatted socket address
93 @param addr_len length of socket address
94*/
95
96static inline void mysql_socket_set_address(
98 MYSQL_SOCKET socket, const struct sockaddr *addr, socklen_t addr_len
99#else
100 MYSQL_SOCKET socket [[maybe_unused]],
101 const struct sockaddr *addr [[maybe_unused]],
102 socklen_t addr_len [[maybe_unused]]
103#endif
104) {
105#ifdef HAVE_PSI_SOCKET_INTERFACE
106 if (socket.m_psi != nullptr) {
107 /* Always update state, no m_enabled check. */
108 PSI_SOCKET_CALL(set_socket_info)(socket.m_psi, &socket.fd, addr, addr_len);
109 }
110#endif
111}
112
113/**
114 Assign the current thread instrumentation to the socket.
115 @param socket instrumented socket
116*/
120#else
121 MYSQL_SOCKET socket [[maybe_unused]]
122#endif
123) {
124#ifdef HAVE_PSI_SOCKET_INTERFACE
125 if (socket.m_psi != nullptr) {
126 /* Always update state, no m_enabled check. */
127 PSI_SOCKET_CALL(set_socket_thread_owner)(socket.m_psi);
128 }
129#endif
130}
131
132/**
133 MYSQL_SOCKET helper. Get socket descriptor.
134 @param mysql_socket Instrumented socket
135 @sa mysql_socket_setfd
136*/
137static inline my_socket mysql_socket_getfd(MYSQL_SOCKET mysql_socket) {
138 return mysql_socket.fd;
139}
140
141/**
142 MYSQL_SOCKET helper. Set socket descriptor.
143 @param mysql_socket Instrumented socket
144 @param fd Socket descriptor
145 @sa mysql_socket_getfd
146*/
147static inline void mysql_socket_setfd(MYSQL_SOCKET *mysql_socket,
148 my_socket fd) {
149 if (likely(mysql_socket != nullptr)) {
150 mysql_socket->fd = fd;
151 }
152}
153
154/**
155 @def MYSQL_SOCKET_WAIT_VARIABLES
156 Instrumentation helper for socket waits.
157 This instrumentation declares local variables.
158 Do not use a ';' after this macro
159 @param LOCKER locker
160 @param STATE locker state
161 @sa MYSQL_START_SOCKET_WAIT.
162 @sa MYSQL_END_SOCKET_WAIT.
163*/
164#ifdef HAVE_PSI_SOCKET_INTERFACE
165#define MYSQL_SOCKET_WAIT_VARIABLES(LOCKER, STATE) \
166 struct PSI_socket_locker *LOCKER; \
167 PSI_socket_locker_state STATE;
168#else
169#define MYSQL_SOCKET_WAIT_VARIABLES(LOCKER, STATE)
170#endif
171
172/**
173 @def MYSQL_START_SOCKET_WAIT
174 Instrumentation helper for socket waits.
175 This instrumentation marks the start of a wait event.
176 @param LOCKER locker
177 @param STATE locker state
178 @param SOCKET instrumented socket
179 @param OP The socket operation to be performed
180 @param COUNT bytes to be written/read
181 @sa MYSQL_END_SOCKET_WAIT.
182*/
183#ifdef HAVE_PSI_SOCKET_INTERFACE
184#define MYSQL_START_SOCKET_WAIT(LOCKER, STATE, SOCKET, OP, COUNT) \
185 LOCKER = inline_mysql_start_socket_wait(STATE, SOCKET, OP, COUNT, __FILE__, \
186 __LINE__)
187#else
188#define MYSQL_START_SOCKET_WAIT(LOCKER, STATE, SOCKET, OP, COUNT) \
189 do { \
190 } while (0)
191#endif
192
193/**
194 @def MYSQL_END_SOCKET_WAIT
195 Instrumentation helper for socket waits.
196 This instrumentation marks the end of a wait event.
197 @param LOCKER locker
198 @param COUNT actual bytes written/read, or -1
199 @sa MYSQL_START_SOCKET_WAIT.
200*/
201#ifdef HAVE_PSI_SOCKET_INTERFACE
202#define MYSQL_END_SOCKET_WAIT(LOCKER, COUNT) \
203 inline_mysql_end_socket_wait(LOCKER, COUNT)
204#else
205#define MYSQL_END_SOCKET_WAIT(LOCKER, COUNT) \
206 do { \
207 } while (0)
208#endif
209
210/**
211 @def MYSQL_SOCKET_SET_STATE
212 Set the state (IDLE, ACTIVE) of an instrumented socket.
213 @param SOCKET the instrumented socket
214 @param STATE the new state
215 @sa PSI_socket_state
216*/
217#ifdef HAVE_PSI_SOCKET_INTERFACE
218#define MYSQL_SOCKET_SET_STATE(SOCKET, STATE) \
219 inline_mysql_socket_set_state(SOCKET, STATE)
220#else
221#define MYSQL_SOCKET_SET_STATE(SOCKET, STATE) \
222 do { \
223 } while (0)
224#endif
225
226#ifdef HAVE_PSI_SOCKET_INTERFACE
227/**
228 Instrumentation calls for MYSQL_START_SOCKET_WAIT.
229 @sa MYSQL_START_SOCKET_WAIT.
230*/
232 PSI_socket_locker_state *state, MYSQL_SOCKET mysql_socket,
233 enum PSI_socket_operation op, size_t byte_count, const char *src_file,
234 int src_line) {
235 if (mysql_socket.m_psi != nullptr) {
236 if (mysql_socket.m_psi->m_enabled) {
237 struct PSI_socket_locker *locker;
238 locker = PSI_SOCKET_CALL(start_socket_wait)(
239 state, mysql_socket.m_psi, op, byte_count, src_file, src_line);
240 return locker;
241 }
242 }
243
244 return nullptr;
245}
246
247/**
248 Instrumentation calls for MYSQL_END_SOCKET_WAIT.
249 @sa MYSQL_END_SOCKET_WAIT.
250*/
252 struct PSI_socket_locker *locker, size_t byte_count) {
253 if (locker != nullptr) {
254 PSI_SOCKET_CALL(end_socket_wait)(locker, byte_count);
255 }
256}
257
258/**
259 Set the state (IDLE, ACTIVE) of an instrumented socket.
260 @param socket the instrumented socket
261 @param state the new state
262 @sa PSI_socket_state
263*/
265 enum PSI_socket_state state) {
266 if (socket.m_psi != nullptr) {
267 /* Always update state, no m_enabled check. */
268 PSI_SOCKET_CALL(set_socket_state)(socket.m_psi, state);
269 }
270}
271#endif /* HAVE_PSI_SOCKET_INTERFACE */
272
273/**
274 @def mysql_socket_socket(K, D, T, P)
275 Create a socket.
276 @c mysql_socket_socket is a replacement for @c socket.
277 @param K PSI_socket_key for this instrumented socket
278 @param D Socket domain
279 @param T Protocol type
280 @param P Transport protocol
281*/
282
283#ifdef HAVE_PSI_SOCKET_INTERFACE
284#define mysql_socket_socket(K, D, T, P) inline_mysql_socket_socket(K, D, T, P)
285#else
286#define mysql_socket_socket(K, D, T, P) inline_mysql_socket_socket(D, T, P)
287#endif
288
289/**
290 @def mysql_socket_bind(FD, AP, L)
291 Bind a socket to a local port number and IP address
292 @c mysql_socket_bind is a replacement for @c bind.
293 @param FD Instrumented socket descriptor returned by socket()
294 @param AP Pointer to local port number and IP address in sockaddr structure
295 @param L Length of sockaddr structure
296*/
297#ifdef HAVE_PSI_SOCKET_INTERFACE
298#define mysql_socket_bind(FD, AP, L) \
299 inline_mysql_socket_bind(__FILE__, __LINE__, FD, AP, L)
300#else
301#define mysql_socket_bind(FD, AP, L) inline_mysql_socket_bind(FD, AP, L)
302#endif
303
304/**
305 @def mysql_socket_getsockname(FD, AP, LP)
306 Return port number and IP address of the local host
307 @c mysql_socket_getsockname is a replacement for @c getsockname.
308 @param FD Instrumented socket descriptor returned by socket()
309 @param AP Pointer to returned address of local host in @c sockaddr structure
310 @param LP Pointer to length of @c sockaddr structure
311*/
312#ifdef HAVE_PSI_SOCKET_INTERFACE
313#define mysql_socket_getsockname(FD, AP, LP) \
314 inline_mysql_socket_getsockname(__FILE__, __LINE__, FD, AP, LP)
315#else
316#define mysql_socket_getsockname(FD, AP, LP) \
317 inline_mysql_socket_getsockname(FD, AP, LP)
318#endif
319
320/**
321 @def mysql_socket_connect(FD, AP, L)
322 Establish a connection to a remote host.
323 @c mysql_socket_connect is a replacement for @c connect.
324 @param FD Instrumented socket descriptor returned by socket()
325 @param AP Pointer to target address in sockaddr structure
326 @param L Length of sockaddr structure
327*/
328#ifdef HAVE_PSI_SOCKET_INTERFACE
329#define mysql_socket_connect(FD, AP, L) \
330 inline_mysql_socket_connect(__FILE__, __LINE__, FD, AP, L)
331#else
332#define mysql_socket_connect(FD, AP, L) inline_mysql_socket_connect(FD, AP, L)
333#endif
334
335/**
336 @def mysql_socket_getpeername(FD, AP, LP)
337 Get port number and IP address of remote host that a socket is connected to.
338 @c mysql_socket_getpeername is a replacement for @c getpeername.
339 @param FD Instrumented socket descriptor returned by socket() or accept()
340 @param AP Pointer to returned address of remote host in sockaddr structure
341 @param LP Pointer to length of sockaddr structure
342*/
343#ifdef HAVE_PSI_SOCKET_INTERFACE
344#define mysql_socket_getpeername(FD, AP, LP) \
345 inline_mysql_socket_getpeername(__FILE__, __LINE__, FD, AP, LP)
346#else
347#define mysql_socket_getpeername(FD, AP, LP) \
348 inline_mysql_socket_getpeername(FD, AP, LP)
349#endif
350
351/**
352 @def mysql_socket_send(FD, B, N, FL)
353 Send data from the buffer, B, to a connected socket.
354 @c mysql_socket_send is a replacement for @c send.
355 @param FD Instrumented socket descriptor returned by socket() or accept()
356 @param B Buffer to send
357 @param N Number of bytes to send
358 @param FL Control flags
359*/
360#ifdef HAVE_PSI_SOCKET_INTERFACE
361#define mysql_socket_send(FD, B, N, FL) \
362 inline_mysql_socket_send(__FILE__, __LINE__, FD, B, N, FL)
363#else
364#define mysql_socket_send(FD, B, N, FL) inline_mysql_socket_send(FD, B, N, FL)
365#endif
366
367/**
368 @def mysql_socket_recv(FD, B, N, FL)
369 Receive data from a connected socket.
370 @c mysql_socket_recv is a replacement for @c recv.
371 @param FD Instrumented socket descriptor returned by socket() or accept()
372 @param B Buffer to receive to
373 @param N Maximum bytes to receive
374 @param FL Control flags
375*/
376#ifdef HAVE_PSI_SOCKET_INTERFACE
377#define mysql_socket_recv(FD, B, N, FL) \
378 inline_mysql_socket_recv(__FILE__, __LINE__, FD, B, N, FL)
379#else
380#define mysql_socket_recv(FD, B, N, FL) inline_mysql_socket_recv(FD, B, N, FL)
381#endif
382
383/**
384 @def mysql_socket_sendto(FD, B, N, FL, AP, L)
385 Send data to a socket at the specified address.
386 @c mysql_socket_sendto is a replacement for @c sendto.
387 @param FD Instrumented socket descriptor returned by socket()
388 @param B Buffer to send
389 @param N Number of bytes to send
390 @param FL Control flags
391 @param AP Pointer to destination sockaddr structure
392 @param L Size of sockaddr structure
393*/
394#ifdef HAVE_PSI_SOCKET_INTERFACE
395#define mysql_socket_sendto(FD, B, N, FL, AP, L) \
396 inline_mysql_socket_sendto(__FILE__, __LINE__, FD, B, N, FL, AP, L)
397#else
398#define mysql_socket_sendto(FD, B, N, FL, AP, L) \
399 inline_mysql_socket_sendto(FD, B, N, FL, AP, L)
400#endif
401
402/**
403 @def mysql_socket_recvfrom(FD, B, N, FL, AP, L)
404 Receive data from a socket and return source address information
405 @c mysql_socket_recvfrom is a replacement for @c recvfrom.
406 @param FD Instrumented socket descriptor returned by socket()
407 @param B Buffer to receive to
408 @param N Maximum bytes to receive
409 @param FL Control flags
410 @param AP Pointer to source address in sockaddr_storage structure
411 @param LP Size of sockaddr_storage structure
412*/
413#ifdef HAVE_PSI_SOCKET_INTERFACE
414#define mysql_socket_recvfrom(FD, B, N, FL, AP, LP) \
415 inline_mysql_socket_recvfrom(__FILE__, __LINE__, FD, B, N, FL, AP, LP)
416#else
417#define mysql_socket_recvfrom(FD, B, N, FL, AP, LP) \
418 inline_mysql_socket_recvfrom(FD, B, N, FL, AP, LP)
419#endif
420
421/**
422 @def mysql_socket_getsockopt(FD, LV, ON, OP, OL)
423 Get a socket option for the specified socket.
424 @c mysql_socket_getsockopt is a replacement for @c getsockopt.
425 @param FD Instrumented socket descriptor returned by socket()
426 @param LV Protocol level
427 @param ON Option to query
428 @param OP Buffer which will contain the value for the requested option
429 @param OL Pointer to length of OP
430*/
431#ifdef HAVE_PSI_SOCKET_INTERFACE
432#define mysql_socket_getsockopt(FD, LV, ON, OP, OL) \
433 inline_mysql_socket_getsockopt(__FILE__, __LINE__, FD, LV, ON, OP, OL)
434#else
435#define mysql_socket_getsockopt(FD, LV, ON, OP, OL) \
436 inline_mysql_socket_getsockopt(FD, LV, ON, OP, OL)
437#endif
438
439/**
440 @def mysql_socket_setsockopt(FD, LV, ON, OP, OL)
441 Set a socket option for the specified socket.
442 @c mysql_socket_setsockopt is a replacement for @c setsockopt.
443 @param FD Instrumented socket descriptor returned by socket()
444 @param LV Protocol level
445 @param ON Option to modify
446 @param OP Buffer containing the value for the specified option
447 @param OL Pointer to length of OP
448*/
449#ifdef HAVE_PSI_SOCKET_INTERFACE
450#define mysql_socket_setsockopt(FD, LV, ON, OP, OL) \
451 inline_mysql_socket_setsockopt(__FILE__, __LINE__, FD, LV, ON, OP, OL)
452#else
453#define mysql_socket_setsockopt(FD, LV, ON, OP, OL) \
454 inline_mysql_socket_setsockopt(FD, LV, ON, OP, OL)
455#endif
456
457/**
458 @def mysql_sock_set_nonblocking
459 Set socket to non-blocking.
460 @param FD instrumented socket descriptor
461*/
462#ifdef HAVE_PSI_SOCKET_INTERFACE
463#define mysql_sock_set_nonblocking(FD) \
464 inline_mysql_sock_set_nonblocking(__FILE__, __LINE__, FD)
465#else
466#define mysql_sock_set_nonblocking(FD) inline_mysql_sock_set_nonblocking(FD)
467#endif
468
469/**
470 @def mysql_socket_listen(FD, N)
471 Set socket state to listen for an incoming connection.
472 @c mysql_socket_listen is a replacement for @c listen.
473 @param FD Instrumented socket descriptor, bound and connected
474 @param N Maximum number of pending connections allowed.
475*/
476#ifdef HAVE_PSI_SOCKET_INTERFACE
477#define mysql_socket_listen(FD, N) \
478 inline_mysql_socket_listen(__FILE__, __LINE__, FD, N)
479#else
480#define mysql_socket_listen(FD, N) inline_mysql_socket_listen(FD, N)
481#endif
482
483/**
484 @def mysql_socket_accept(K, FD, AP, LP)
485 Accept a connection from any remote host; TCP only.
486 @c mysql_socket_accept is a replacement for @c accept.
487 @param K PSI_socket_key for this instrumented socket
488 @param FD Instrumented socket descriptor, bound and placed in a listen state
489 @param AP Pointer to sockaddr structure with returned IP address and port of
490 connected host
491 @param LP Pointer to length of valid information in AP
492*/
493#ifdef HAVE_PSI_SOCKET_INTERFACE
494#define mysql_socket_accept(K, FD, AP, LP) \
495 inline_mysql_socket_accept(__FILE__, __LINE__, K, FD, AP, LP)
496#else
497#define mysql_socket_accept(K, FD, AP, LP) \
498 inline_mysql_socket_accept(FD, AP, LP)
499#endif
500
501/**
502 @def mysql_socket_close(FD)
503 Close a socket and sever any connections.
504 @c mysql_socket_close is a replacement for @c close.
505 @param FD Instrumented socket descriptor returned by socket() or accept()
506*/
507#ifdef HAVE_PSI_SOCKET_INTERFACE
508#define mysql_socket_close(FD) inline_mysql_socket_close(__FILE__, __LINE__, FD)
509#else
510#define mysql_socket_close(FD) inline_mysql_socket_close(FD)
511#endif
512
513/**
514 @def mysql_socket_shutdown(FD, H)
515 Disable receives and/or sends on a socket.
516 @c mysql_socket_shutdown is a replacement for @c shutdown.
517 @param FD Instrumented socket descriptor returned by socket() or accept()
518 @param H Specifies which operations to shutdown
519*/
520#ifdef HAVE_PSI_SOCKET_INTERFACE
521#define mysql_socket_shutdown(FD, H) \
522 inline_mysql_socket_shutdown(__FILE__, __LINE__, FD, H)
523#else
524#define mysql_socket_shutdown(FD, H) inline_mysql_socket_shutdown(FD, H)
525#endif
526
527#ifdef HAVE_PSI_SOCKET_INTERFACE
528static inline void inline_mysql_socket_register(const char *category,
530 int count) {
531 PSI_SOCKET_CALL(register_socket)(category, info, count);
532}
533#endif
534
535/** mysql_socket_socket */
536
540#endif
541 int domain, int type, int protocol) {
542 MYSQL_SOCKET mysql_socket = MYSQL_INVALID_SOCKET;
543 mysql_socket.fd = socket(domain, type, protocol);
544
545#ifdef HAVE_PSI_SOCKET_INTERFACE
546 if (likely(mysql_socket.fd != INVALID_SOCKET)) {
547 mysql_socket.m_psi = PSI_SOCKET_CALL(init_socket)(
548 key, (const my_socket *)&mysql_socket.fd, nullptr, 0);
549 }
550#endif
551 return mysql_socket;
552}
553
554/** mysql_socket_bind */
555
556static inline int inline_mysql_socket_bind(
558 const char *src_file, uint src_line,
559#endif
560 MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len) {
561 int result;
562
563#ifdef HAVE_PSI_SOCKET_INTERFACE
564 if (mysql_socket.m_psi != nullptr) {
565 if (mysql_socket.m_psi->m_enabled) {
566 /* Instrumentation start */
568 PSI_socket_locker *locker;
569 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
570 PSI_SOCKET_BIND, (size_t)0,
571 src_file, src_line);
572
573 /* Instrumented code */
574 result = bind(mysql_socket.fd, addr, len);
575
576 /* Instrumentation end */
577 if (locker != nullptr) {
578 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
579 }
580
581 if (result == 0) {
582 PSI_SOCKET_CALL(set_socket_info)
583 (mysql_socket.m_psi, nullptr, addr, len);
584 }
585
586 return result;
587 }
588 }
589#endif
590
591 /* Non instrumented code */
592 result = bind(mysql_socket.fd, addr, len);
593
594#ifdef HAVE_PSI_SOCKET_INTERFACE
595 if ((mysql_socket.m_psi != nullptr) && (result == 0)) {
596 PSI_SOCKET_CALL(set_socket_info)(mysql_socket.m_psi, nullptr, addr, len);
597 }
598#endif
599
600 return result;
601}
602
603/** mysql_socket_getsockname */
604
607 const char *src_file, uint src_line,
608#endif
609 MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len) {
610 int result;
611
612#ifdef HAVE_PSI_SOCKET_INTERFACE
613 if (mysql_socket.m_psi != nullptr) {
614 if (mysql_socket.m_psi->m_enabled) {
615 /* Instrumentation start */
616 PSI_socket_locker *locker;
618 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
619 PSI_SOCKET_BIND, (size_t)0,
620 src_file, src_line);
621
622 /* Instrumented code */
623 result = getsockname(mysql_socket.fd, addr, len);
624
625 /* Instrumentation end */
626 if (locker != nullptr) {
627 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
628 }
629
630 return result;
631 }
632 }
633#endif
634
635 /* Non instrumented code */
636 result = getsockname(mysql_socket.fd, addr, len);
637
638 return result;
639}
640
641/** mysql_socket_connect */
642
645 const char *src_file, uint src_line,
646#endif
647 MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len) {
648 int result;
649
650#ifdef HAVE_PSI_SOCKET_INTERFACE
651 if (mysql_socket.m_psi != nullptr) {
652 if (mysql_socket.m_psi->m_enabled) {
653 /* Instrumentation start */
654 PSI_socket_locker *locker;
656 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
657 PSI_SOCKET_CONNECT, (size_t)0,
658 src_file, src_line);
659
660 /* Instrumented code */
661 result = connect(mysql_socket.fd, addr, len);
662
663 /* Instrumentation end */
664 if (locker != nullptr) {
665 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
666 }
667
668 return result;
669 }
670 }
671#endif
672
673 /* Non instrumented code */
674 result = connect(mysql_socket.fd, addr, len);
675
676 return result;
677}
678
679/** mysql_socket_getpeername */
680
683 const char *src_file, uint src_line,
684#endif
685 MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len) {
686 int result;
687
688#ifdef HAVE_PSI_SOCKET_INTERFACE
689 if (mysql_socket.m_psi != nullptr) {
690 if (mysql_socket.m_psi->m_enabled) {
691 /* Instrumentation start */
692 PSI_socket_locker *locker;
694 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
695 PSI_SOCKET_BIND, (size_t)0,
696 src_file, src_line);
697
698 /* Instrumented code */
699 result = getpeername(mysql_socket.fd, addr, len);
700
701 /* Instrumentation end */
702 if (locker != nullptr) {
703 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
704 }
705
706 return result;
707 }
708 }
709#endif
710
711 /* Non instrumented code */
712 result = getpeername(mysql_socket.fd, addr, len);
713
714 return result;
715}
716
717/** mysql_socket_send */
718
719static inline ssize_t inline_mysql_socket_send(
721 const char *src_file, uint src_line,
722#endif
723 MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags) {
724 ssize_t result;
725
726#ifdef HAVE_PSI_SOCKET_INTERFACE
727 if (mysql_socket.m_psi != nullptr) {
728 if (mysql_socket.m_psi->m_enabled) {
729 /* Instrumentation start */
730 PSI_socket_locker *locker;
732 locker = PSI_SOCKET_CALL(start_socket_wait)(
733 &state, mysql_socket.m_psi, PSI_SOCKET_SEND, n, src_file, src_line);
734
735 /* Instrumented code */
736 result = send(mysql_socket.fd, buf, IF_WIN((int), ) n, flags);
737
738 /* Instrumentation end */
739 if (locker != nullptr) {
740 size_t bytes_written;
741 bytes_written = (result > -1) ? result : 0;
742 PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_written);
743 }
744
745 return result;
746 }
747 }
748#endif
749
750 /* Non instrumented code */
751 result = send(mysql_socket.fd, buf, IF_WIN((int), ) n, flags);
752
753 return result;
754}
755
756/** mysql_socket_recv */
757
758static inline ssize_t inline_mysql_socket_recv(
760 const char *src_file, uint src_line,
761#endif
762 MYSQL_SOCKET mysql_socket, SOCKBUF_T *buf, size_t n, int flags) {
763 ssize_t result;
764
765#ifdef HAVE_PSI_SOCKET_INTERFACE
766 if (mysql_socket.m_psi != nullptr) {
767 if (mysql_socket.m_psi->m_enabled) {
768 /* Instrumentation start */
769 PSI_socket_locker *locker;
771 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
772 PSI_SOCKET_RECV, (size_t)0,
773 src_file, src_line);
774
775 /* Instrumented code */
776 result = recv(mysql_socket.fd, buf, IF_WIN((int), ) n, flags);
777
778 /* Instrumentation end */
779 if (locker != nullptr) {
780 size_t bytes_read;
781 bytes_read = (result > -1) ? result : 0;
782 PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_read);
783 }
784
785 return result;
786 }
787 }
788#endif
789
790 /* Non instrumented code */
791 result = recv(mysql_socket.fd, buf, IF_WIN((int), ) n, flags);
792
793 return result;
794}
795
796/** mysql_socket_sendto */
797
798static inline ssize_t inline_mysql_socket_sendto(
800 const char *src_file, uint src_line,
801#endif
802 MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags,
803 const struct sockaddr *addr, socklen_t addr_len) {
804 ssize_t result;
805
806#ifdef HAVE_PSI_SOCKET_INTERFACE
807 if (mysql_socket.m_psi != nullptr) {
808 if (mysql_socket.m_psi->m_enabled) {
809 /* Instrumentation start */
810 PSI_socket_locker *locker;
812 locker = PSI_SOCKET_CALL(start_socket_wait)(
813 &state, mysql_socket.m_psi, PSI_SOCKET_SEND, n, src_file, src_line);
814
815 /* Instrumented code */
816 result = sendto(mysql_socket.fd, buf, IF_WIN((int), ) n, flags, addr,
817 addr_len);
818
819 /* Instrumentation end */
820 if (locker != nullptr) {
821 size_t bytes_written;
822 bytes_written = (result > -1) ? result : 0;
823 PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_written);
824 }
825
826 return result;
827 }
828 }
829#endif
830
831 /* Non instrumented code */
832 result =
833 sendto(mysql_socket.fd, buf, IF_WIN((int), ) n, flags, addr, addr_len);
834
835 return result;
836}
837
838/** mysql_socket_recvfrom */
839
840static inline ssize_t inline_mysql_socket_recvfrom(
842 const char *src_file, uint src_line,
843#endif
844 MYSQL_SOCKET mysql_socket, SOCKBUF_T *buf, size_t n, int flags,
845 struct sockaddr *addr, socklen_t *addr_len) {
846 ssize_t result;
847
848#ifdef HAVE_PSI_SOCKET_INTERFACE
849 if (mysql_socket.m_psi != nullptr) {
850 if (mysql_socket.m_psi->m_enabled) {
851 /* Instrumentation start */
852 PSI_socket_locker *locker;
854 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
855 PSI_SOCKET_RECV, (size_t)0,
856 src_file, src_line);
857
858 /* Instrumented code */
859 result = recvfrom(mysql_socket.fd, buf, IF_WIN((int), ) n, flags, addr,
860 addr_len);
861
862 /* Instrumentation end */
863 if (locker != nullptr) {
864 size_t bytes_read;
865 bytes_read = (result > -1) ? result : 0;
866 PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_read);
867 }
868
869 return result;
870 }
871 }
872#endif
873
874 /* Non instrumented code */
875 result =
876 recvfrom(mysql_socket.fd, buf, IF_WIN((int), ) n, flags, addr, addr_len);
877
878 return result;
879}
880
881/** mysql_socket_getsockopt */
882
885 const char *src_file, uint src_line,
886#endif
887 MYSQL_SOCKET mysql_socket, int level, int optname, SOCKBUF_T *optval,
888 socklen_t *optlen) {
889 int result;
890
891#ifdef HAVE_PSI_SOCKET_INTERFACE
892 if (mysql_socket.m_psi != nullptr) {
893 if (mysql_socket.m_psi->m_enabled) {
894 /* Instrumentation start */
895 PSI_socket_locker *locker;
897 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
898 PSI_SOCKET_OPT, (size_t)0,
899 src_file, src_line);
900
901 /* Instrumented code */
902 result = getsockopt(mysql_socket.fd, level, optname, optval, optlen);
903
904 /* Instrumentation end */
905 if (locker != nullptr) {
906 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
907 }
908
909 return result;
910 }
911 }
912#endif
913
914 /* Non instrumented code */
915 result = getsockopt(mysql_socket.fd, level, optname, optval, optlen);
916
917 return result;
918}
919
920/** mysql_socket_setsockopt */
921
924 const char *src_file, uint src_line,
925#endif
926 MYSQL_SOCKET mysql_socket, int level, int optname, const SOCKBUF_T *optval,
927 socklen_t optlen) {
928 int result;
929
930#ifdef HAVE_PSI_SOCKET_INTERFACE
931 if (mysql_socket.m_psi != nullptr) {
932 if (mysql_socket.m_psi->m_enabled) {
933 /* Instrumentation start */
934 PSI_socket_locker *locker;
936 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
937 PSI_SOCKET_OPT, (size_t)0,
938 src_file, src_line);
939
940 /* Instrumented code */
941 result = setsockopt(mysql_socket.fd, level, optname, optval, optlen);
942
943 /* Instrumentation end */
944 if (locker != nullptr) {
945 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
946 }
947
948 return result;
949 }
950 }
951#endif
952
953 /* Non instrumented code */
954 result = setsockopt(mysql_socket.fd, level, optname, optval, optlen);
955
956 return result;
957}
958
959/** set_socket_nonblock */
960static inline int set_socket_nonblock(my_socket fd) {
961 int ret = 0;
962#ifdef _WIN32
963 {
964 u_long nonblocking = 1;
965 ret = ioctlsocket(fd, FIONBIO, &nonblocking);
966 }
967#else
968 {
969 int fd_flags;
970 fd_flags = fcntl(fd, F_GETFL, 0);
971 if (fd_flags < 0) {
972 return errno;
973 }
974#if defined(O_NONBLOCK)
975 fd_flags |= O_NONBLOCK;
976#elif defined(O_NDELAY)
977 fd_flags |= O_NDELAY;
978#elif defined(O_FNDELAY)
979 fd_flags |= O_FNDELAY;
980#else
981#error "No definition of non-blocking flag found."
982#endif /* O_NONBLOCK */
983 if (fcntl(fd, F_SETFL, fd_flags) == -1) {
984 ret = errno;
985 }
986 }
987#endif /* _WIN32 */
988 return ret;
989}
990
991/** mysql_socket_set_nonblocking */
992
995 const char *src_file, uint src_line,
996#endif
997 MYSQL_SOCKET mysql_socket) {
998 int result = 0;
999
1000#ifdef HAVE_PSI_SOCKET_INTERFACE
1001 if (mysql_socket.m_psi != nullptr) {
1002 if (mysql_socket.m_psi->m_enabled) {
1003 /* Instrumentation start */
1004 PSI_socket_locker *locker;
1006 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
1007 PSI_SOCKET_OPT, (size_t)0,
1008 src_file, src_line);
1009
1010 /* Instrumented code */
1011 result = set_socket_nonblock(mysql_socket.fd);
1012
1013 /* Instrumentation end */
1014 if (locker != nullptr) {
1015 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
1016 }
1017
1018 return result;
1019 }
1020 }
1021#endif
1022
1023 /* Non instrumented code */
1024 result = set_socket_nonblock(mysql_socket.fd);
1025
1026 return result;
1027}
1028
1029/** mysql_socket_listen */
1030
1033 const char *src_file, uint src_line,
1034#endif
1035 MYSQL_SOCKET mysql_socket, int backlog) {
1036 int result;
1037
1038#ifdef HAVE_PSI_SOCKET_INTERFACE
1039 if (mysql_socket.m_psi != nullptr) {
1040 if (mysql_socket.m_psi->m_enabled) {
1041 /* Instrumentation start */
1042 PSI_socket_locker *locker;
1044 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
1045 PSI_SOCKET_CONNECT, (size_t)0,
1046 src_file, src_line);
1047
1048 /* Instrumented code */
1049 result = listen(mysql_socket.fd, backlog);
1050
1051 /* Instrumentation end */
1052 if (locker != nullptr) {
1053 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
1054 }
1055
1056 return result;
1057 }
1058 }
1059#endif
1060
1061 /* Non instrumented code */
1062 result = listen(mysql_socket.fd, backlog);
1063
1064 return result;
1065}
1066
1067/** mysql_socket_accept */
1068
1071 const char *src_file, uint src_line, PSI_socket_key key,
1072#endif
1073 MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len) {
1074 MYSQL_SOCKET socket_accept = MYSQL_INVALID_SOCKET;
1075 socklen_t addr_length = (addr_len != nullptr) ? *addr_len : 0;
1076
1077#ifdef HAVE_PSI_SOCKET_INTERFACE
1078 if (socket_listen.m_psi != nullptr) {
1079 if (socket_listen.m_psi->m_enabled) {
1080 /* Instrumentation start */
1081 PSI_socket_locker *locker;
1083 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, socket_listen.m_psi,
1084 PSI_SOCKET_CONNECT, (size_t)0,
1085 src_file, src_line);
1086
1087 /* Instrumented code */
1088 socket_accept.fd = accept(socket_listen.fd, addr, &addr_length);
1089
1090 /* Instrumentation end */
1091 if (locker != nullptr) {
1092 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
1093 }
1094
1095 if (likely(socket_accept.fd != INVALID_SOCKET)) {
1096 /* Initialize the instrument with the new socket descriptor and address
1097 */
1098 socket_accept.m_psi = PSI_SOCKET_CALL(init_socket)(
1099 key, (const my_socket *)&socket_accept.fd, addr, addr_length);
1100 }
1101
1102 return socket_accept;
1103 }
1104 }
1105#endif
1106
1107 /* Non instrumented code */
1108 socket_accept.fd = accept(socket_listen.fd, addr, &addr_length);
1109
1110#ifdef HAVE_PSI_SOCKET_INTERFACE
1111 if (likely(socket_accept.fd != INVALID_SOCKET)) {
1112 /* Initialize the instrument with the new socket descriptor and address */
1113 socket_accept.m_psi = PSI_SOCKET_CALL(init_socket)(
1114 key, (const my_socket *)&socket_accept.fd, addr, addr_length);
1115 }
1116#endif
1117
1118 return socket_accept;
1119}
1120
1121/** mysql_socket_close */
1122
1125 const char *src_file, uint src_line,
1126#endif
1127 MYSQL_SOCKET mysql_socket) {
1128 int result;
1129
1130#ifdef HAVE_PSI_SOCKET_INTERFACE
1131 if (mysql_socket.m_psi != nullptr) {
1132 if (mysql_socket.m_psi->m_enabled) {
1133 /* Instrumentation start */
1134 PSI_socket_locker *locker;
1136 locker = PSI_SOCKET_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
1137 PSI_SOCKET_CLOSE, (size_t)0,
1138 src_file, src_line);
1139
1140 /* Instrumented code */
1141 result = closesocket(mysql_socket.fd);
1142
1143 /* Instrumentation end */
1144 if (locker != nullptr) {
1145 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
1146 }
1147
1148 /* Remove the instrumentation for this socket. */
1149 PSI_SOCKET_CALL(destroy_socket)(mysql_socket.m_psi);
1150
1151 return result;
1152 }
1153 }
1154#endif
1155
1156 /* Non instrumented code */
1157 result = closesocket(mysql_socket.fd);
1158
1159#ifdef HAVE_PSI_SOCKET_INTERFACE
1160 /* Remove the instrumentation for this socket. */
1161 if (mysql_socket.m_psi != nullptr) {
1162 PSI_SOCKET_CALL(destroy_socket)(mysql_socket.m_psi);
1163 }
1164#endif
1165
1166 return result;
1167}
1168
1169/** mysql_socket_shutdown */
1170
1173 const char *src_file, uint src_line,
1174#endif
1175 MYSQL_SOCKET mysql_socket, int how) {
1176 int result;
1177
1178#ifdef _WIN32
1179 static LPFN_DISCONNECTEX DisconnectEx = NULL;
1180 if (DisconnectEx == NULL) {
1181 DWORD dwBytesReturned;
1182 GUID guidDisconnectEx = WSAID_DISCONNECTEX;
1183 WSAIoctl(mysql_socket.fd, SIO_GET_EXTENSION_FUNCTION_POINTER,
1184 &guidDisconnectEx, sizeof(GUID), &DisconnectEx,
1185 sizeof(DisconnectEx), &dwBytesReturned, NULL, NULL);
1186 }
1187#endif
1188
1189/* Instrumentation start */
1190#ifdef HAVE_PSI_SOCKET_INTERFACE
1191 if (mysql_socket.m_psi != nullptr) {
1192 if (mysql_socket.m_psi->m_enabled) {
1193 PSI_socket_locker *locker;
1195 locker = PSI_SOCKET_CALL(start_socket_wait)(
1196 &state, mysql_socket.m_psi, PSI_SOCKET_SHUTDOWN, (size_t)0, src_file,
1197 src_line);
1198
1199/* Instrumented code */
1200#ifdef _WIN32
1201 if (DisconnectEx)
1202 result = (DisconnectEx(mysql_socket.fd, (LPOVERLAPPED)NULL, (DWORD)0,
1203 (DWORD)0) == TRUE)
1204 ? 0
1205 : -1;
1206 else
1207#endif
1208 result = shutdown(mysql_socket.fd, how);
1209
1210 /* Instrumentation end */
1211 if (locker != nullptr) {
1212 PSI_SOCKET_CALL(end_socket_wait)(locker, (size_t)0);
1213 }
1214
1215 return result;
1216 }
1217 }
1218#endif
1219
1220/* Non instrumented code */
1221#ifdef _WIN32
1222 if (DisconnectEx)
1223 result = (DisconnectEx(mysql_socket.fd, (LPOVERLAPPED)NULL, (DWORD)0,
1224 (DWORD)0) == TRUE)
1225 ? 0
1226 : -1;
1227 else
1228#endif
1229 result = shutdown(mysql_socket.fd, how);
1230
1231 return result;
1232}
1233
1234/** @} (end of group psi_api_socket) */
1235
1236#endif
#define PSI_SOCKET_CALL(M)
Definition: psi_socket.h:36
mysql_service_status_t recv(const char *tag, const unsigned char *data, size_t data_length) noexcept
Definition: gr_message_service_example.cc:39
void destroy_socket(PFS_socket *pfs)
Destroy instrumentation for a socket instance.
Definition: pfs_instr.cc:1502
PSI_socket_operation
Operation performed on an instrumented socket.
Definition: psi_socket_bits.h:89
struct PSI_socket_locker PSI_socket_locker
Definition: psi_socket_bits.h:77
PSI_socket_state
State of an instrumented socket.
Definition: psi_socket_bits.h:80
unsigned int PSI_socket_key
Instrumented socket key.
Definition: psi_socket_bits.h:49
@ PSI_SOCKET_CLOSE
Socket close, as in shutdown().
Definition: psi_socket_bits.h:97
@ PSI_SOCKET_SEND
Socket send, send().
Definition: psi_socket_bits.h:99
@ PSI_SOCKET_RECV
Socket receive, recv().
Definition: psi_socket_bits.h:101
@ PSI_SOCKET_BIND
Socket bind, as in bind(), getsockname() and getpeername().
Definition: psi_socket_bits.h:95
@ PSI_SOCKET_CONNECT
Socket connection, as in connect(), listen() and accept().
Definition: psi_socket_bits.h:93
@ PSI_SOCKET_SHUTDOWN
Socket shutdown, as in shutdown().
Definition: psi_socket_bits.h:117
@ PSI_SOCKET_OPT
Socket options, as in getsockopt() and setsockopt().
Definition: psi_socket_bits.h:113
static int inline_mysql_socket_getsockopt(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, int level, int optname, SOCKBUF_T *optval, socklen_t *optlen)
mysql_socket_getsockopt
Definition: mysql_socket.h:883
static void inline_mysql_end_socket_wait(struct PSI_socket_locker *locker, size_t byte_count)
Instrumentation calls for MYSQL_END_SOCKET_WAIT.
Definition: mysql_socket.h:251
static ssize_t inline_mysql_socket_sendto(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags, const struct sockaddr *addr, socklen_t addr_len)
mysql_socket_sendto
Definition: mysql_socket.h:798
static int inline_mysql_socket_getpeername(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len)
mysql_socket_getpeername
Definition: mysql_socket.h:681
static int inline_mysql_socket_bind(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len)
mysql_socket_bind
Definition: mysql_socket.h:556
static int inline_mysql_socket_setsockopt(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, int level, int optname, const SOCKBUF_T *optval, socklen_t optlen)
mysql_socket_setsockopt
Definition: mysql_socket.h:922
static struct PSI_socket_locker * inline_mysql_start_socket_wait(PSI_socket_locker_state *state, MYSQL_SOCKET mysql_socket, enum PSI_socket_operation op, size_t byte_count, const char *src_file, int src_line)
Instrumentation calls for MYSQL_START_SOCKET_WAIT.
Definition: mysql_socket.h:231
static int inline_mysql_sock_set_nonblocking(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket)
mysql_socket_set_nonblocking
Definition: mysql_socket.h:993
static void inline_mysql_socket_register(const char *category, PSI_socket_info *info, int count)
Definition: mysql_socket.h:528
static ssize_t inline_mysql_socket_recv(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, SOCKBUF_T *buf, size_t n, int flags)
mysql_socket_recv
Definition: mysql_socket.h:758
static MYSQL_SOCKET inline_mysql_socket_socket(PSI_socket_key key, int domain, int type, int protocol)
mysql_socket_socket
Definition: mysql_socket.h:537
static int inline_mysql_socket_shutdown(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, int how)
mysql_socket_shutdown
Definition: mysql_socket.h:1171
static void mysql_socket_setfd(MYSQL_SOCKET *mysql_socket, my_socket fd)
MYSQL_SOCKET helper.
Definition: mysql_socket.h:147
static int set_socket_nonblock(my_socket fd)
set_socket_nonblock
Definition: mysql_socket.h:960
static MYSQL_SOCKET inline_mysql_socket_accept(const char *src_file, uint src_line, PSI_socket_key key, MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len)
mysql_socket_accept
Definition: mysql_socket.h:1069
static void mysql_socket_set_thread_owner(MYSQL_SOCKET socket)
Assign the current thread instrumentation to the socket.
Definition: mysql_socket.h:117
static ssize_t inline_mysql_socket_send(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags)
mysql_socket_send
Definition: mysql_socket.h:719
static void inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state)
Set the state (IDLE, ACTIVE) of an instrumented socket.
Definition: mysql_socket.h:264
static ssize_t inline_mysql_socket_recvfrom(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, SOCKBUF_T *buf, size_t n, int flags, struct sockaddr *addr, socklen_t *addr_len)
mysql_socket_recvfrom
Definition: mysql_socket.h:840
static void mysql_socket_set_address(MYSQL_SOCKET socket, const struct sockaddr *addr, socklen_t addr_len)
Set socket descriptor and address.
Definition: mysql_socket.h:96
static int inline_mysql_socket_getsockname(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len)
mysql_socket_getsockname
Definition: mysql_socket.h:605
static int inline_mysql_socket_connect(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len)
mysql_socket_connect
Definition: mysql_socket.h:643
static int inline_mysql_socket_close(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket)
mysql_socket_close
Definition: mysql_socket.h:1123
static my_socket mysql_socket_getfd(MYSQL_SOCKET mysql_socket)
MYSQL_SOCKET helper.
Definition: mysql_socket.h:137
static int inline_mysql_socket_listen(const char *src_file, uint src_line, MYSQL_SOCKET mysql_socket, int backlog)
mysql_socket_listen
Definition: mysql_socket.h:1031
static int flags[50]
Definition: hp_test1.cc:40
mysql_service_status_t send(const char *tag, const unsigned char *data, const size_t data_length) noexcept
Definition: message_service.cc:32
Header for compiler-dependent features.
constexpr bool likely(bool expr)
Definition: my_compiler.h:55
Common #defines and includes for file and socket I/O.
#define INVALID_SOCKET
Definition: my_io.h:190
#define closesocket(A)
Definition: my_io.h:178
Some common macros.
#define IF_WIN(A, B)
Definition: my_macros.h:38
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
#define HAVE_PSI_SOCKET_INTERFACE
Definition: my_psi_config.h:197
static int count
Definition: myisam_ftdump.cc:43
int my_socket
Definition: mysql.h:65
#define SOCKBUF_T
Definition: mysql_socket.h:55
#define MYSQL_INVALID_SOCKET
MYSQL_SOCKET initial value.
Definition: mysql_socket_bits.h:52
Log info(cout, "NOTE")
Definition: buf0block_hint.cc:30
stdx::expected< int, std::error_code > fcntl(file_handle_type fd, const FileControlOption &cmd)
Definition: file.h:125
stdx::expected< void, error_type > listen(native_handle_type native_handle, int backlog)
Definition: socket.h:149
stdx::expected< void, error_type > getsockname(native_handle_type native_handle, struct sockaddr *addr, size_t *addr_len)
Definition: socket.h:403
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:63
stdx::expected< void, error_type > bind(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len)
wrap bind() in a portable way.
Definition: socket.h:339
stdx::expected< void, error_type > getpeername(native_handle_type native_handle, struct sockaddr *addr, size_t *addr_len)
Definition: socket.h:424
stdx::expected< native_handle_type, error_type > accept(native_handle_type native_handle, struct sockaddr *addr, socklen_t *addr_len)
wrap accept() in a portable way.
Definition: socket.h:367
stdx::expected< void, error_type > setsockopt(native_handle_type native_handle, int level, int optname, const void *optval, socklen_t optlen)
Definition: socket.h:158
stdx::expected< void, error_type > connect(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len)
wrap connect() in a portable way.
Definition: socket.h:353
stdx::expected< void, error_type > shutdown(native_handle_type fd, int how)
Definition: socket.h:663
stdx::expected< void, error_type > getsockopt(native_handle_type native_handle, int level, int optname, void *optval, socklen_t *optlen)
Definition: socket.h:174
static const char * category
Definition: sha2_password.cc:170
Performance schema instrumentation (declarations).
struct result result
Definition: result.h:34
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:34
struct sockaddr sockaddr
Definition: sock_probe_win32.h:63
An instrumented socket.
Definition: mysql_socket_bits.h:35
struct PSI_socket * m_psi
The instrumentation hook.
Definition: mysql_socket_bits.h:44
my_socket fd
The real socket descriptor.
Definition: mysql_socket_bits.h:37
bool m_enabled
Instrumentation is enabled.
Definition: psi_bits.h:191
Socket instrument information.
Definition: psi_socket_bits.h:128
State data storage for start_socket_wait_v1_t.
Definition: psi_socket_bits.h:158
Definition: result.h:30
#define NULL
Definition: types.h:55
__u_long u_long
Definition: types.h:74
#define TRUE
Definition: types.h:51
unsigned int uint
Definition: uca9-dump.cc:75
int n
Definition: xcom_base.cc:509