Skip to content

Commit

Permalink
wl#9819 patch #2 : Misc. housekeeping required for worklog
Browse files Browse the repository at this point in the history
 (A) move ndb_basename into utility library
 (B) new portability function ndb_getsockname()
  • Loading branch information
jdduncan committed Mar 30, 2017
1 parent f51bd28 commit 92f3f38
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 25 deletions.
11 changes: 10 additions & 1 deletion storage/ndb/include/portlib/ndb_socket_posix.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -201,6 +201,15 @@ int my_getpeername(ndb_socket_t s, struct sockaddr *a, socket_len_t *addrlen)
return 0;
}

static inline
int ndb_getsockname(ndb_socket_t s, struct sockaddr *a, socket_len_t *addrlen)
{
if(getsockname(s.fd, a, addrlen))
return 1;

return 0;
}

static inline int my_shutdown(ndb_socket_t s, int how)
{
return shutdown(s.fd, how);
Expand Down
11 changes: 10 additions & 1 deletion storage/ndb/include/portlib/ndb_socket_win32.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -192,6 +192,15 @@ static inline int my_getpeername(ndb_socket_t s, struct sockaddr *a,
return 0;
}

static inline int ndb_getsockname(ndb_socket_t s, struct sockaddr *a,
socket_len_t *addrlen)
{
if(getsockname(s.s, a, addrlen))
return 1;

return 0;
}

static inline int my_shutdown(ndb_socket_t s, int how)
{
return shutdown(s.s, how);
Expand Down
8 changes: 2 additions & 6 deletions storage/ndb/src/common/portlib/ndb_socket.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -79,11 +79,7 @@ int my_socketpair(ndb_socket_t s[2])
goto err;

/* get sockname */
/*
TODO: if there was a my_getsockname, this wouldnt have to use
definition of my_socket (i.e l.s)
*/
if (getsockname(listener.s, (struct sockaddr*)&addr, &addrlen) < 0)
if (ndb_getsockname(listener, (struct sockaddr*)&addr, &addrlen) != 0)
goto err;

if (my_listen(listener, 1) == -1)
Expand Down
1 change: 1 addition & 0 deletions storage/ndb/src/common/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ADD_DEFINITIONS(-DNO_DUMMY_DECL)
ADD_CONVENIENCE_LIBRARY(ndbgeneral
ndbzio.c
File.cpp
basename.cpp
md5_hash.cpp
Properties.cpp
socket_io.cpp
Expand Down
35 changes: 35 additions & 0 deletions storage/ndb/src/common/util/basename.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <ndb_global.h>

const char *
ndb_basename(const char * path)
{
if (path == NULL)
return NULL;

const char separator = '/';
const char * p = path + strlen(path);
while (p > path && p[0] != separator)
p--;

if (p[0] == separator)
return p + 1;

return p;
}
18 changes: 1 addition & 17 deletions storage/ndb/src/kernel/error/ErrorReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,7 @@ static void dumpJam(FILE* jamStream,
Uint32 thrdTheEmulatedJamIndex,
const JamEvent thrdTheEmulatedJam[]);

static
const char *
ndb_basename(const char * path)
{
if (path == NULL)
return NULL;

const char separator = '/';
const char * p = path + strlen(path);
while (p > path && p[0] != separator)
p--;

if (p[0] == separator)
return p + 1;

return p;
}
const char * ndb_basename(const char *path);

static
const char*
Expand Down

0 comments on commit 92f3f38

Please sign in to comment.