Skip to content

Commit

Permalink
Cherry-pick vio_type_name and safe_vio_type_name functions from 11.2
Browse files Browse the repository at this point in the history
These are taken from the following two commits by Sergei Golubchik <serg@mariadb.org>:

- 7af733a ("perfschema compilation, test and misc fixes")
- 2ac3121 ("perfschema - various collateral cleanups and small changes")
  • Loading branch information
vuvova authored and dlenski committed Jul 3, 2023
1 parent 0ba528f commit e54c24c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/violite.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ enum enum_vio_type
{
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
/* see also vio_type_names[] */
};
#define FIRST_VIO_TYPE VIO_CLOSED
#define LAST_VIO_TYPE VIO_TYPE_SSL

/**
VIO I/O events.
Expand Down Expand Up @@ -173,6 +176,8 @@ void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd);

void vio_end(void);

const char *vio_type_name(enum enum_vio_type vio_type, size_t *len);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ TABLE_FIELD_TYPE mysql_db_table_fields[MYSQL_DB_FIELD_COUNT] = {
const TABLE_FIELD_DEF
mysql_db_table_def= {MYSQL_DB_FIELD_COUNT, mysql_db_table_fields, 0, (uint*) 0 };

const char *safe_vio_type_name(Vio *vio)
{
size_t unused;
#ifdef EMBEDDED_LIBRARY
if (!vio) return "Internal";
#endif
return vio_type_name(vio_type(vio), &unused);
}

static LEX_STRING native_password_plugin_name= {
C_STRING_WITH_LEN("mysql_native_password")
};
Expand Down
20 changes: 20 additions & 0 deletions vio/viosocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,26 @@ enum enum_vio_type vio_type(Vio* vio)
return vio->type;
}

static const LEX_CSTRING vio_type_names[] =
{
{ STRING_WITH_LEN("Error") }, // cannot happen
{ STRING_WITH_LEN("TCP/IP") },
{ STRING_WITH_LEN("Socket") },
{ STRING_WITH_LEN("Named Pipe") },
{ STRING_WITH_LEN("SSL/TLS") },
{ STRING_WITH_LEN("Shared Memory") }
};

const char *vio_type_name(enum enum_vio_type vio_type, size_t *len)
{
int index= vio_type >= FIRST_VIO_TYPE && vio_type <= LAST_VIO_TYPE
? vio_type : 0;

*len= vio_type_names[index].length;
return vio_type_names[index].str;
}


my_socket vio_fd(Vio* vio)
{
return mysql_socket_getfd(vio->mysql_socket);
Expand Down

0 comments on commit e54c24c

Please sign in to comment.