Cosmetic changes to netd client files.

+ Name the dispatch header correctly (NetdClientDispatch.h).
+ Hide the global dispatch variable (__netdClientDispatch).
+ Explain why it's okay to read the variable without locking.
+ Use quotes instead of angle-brackets for non-system includes.
+ Add necessary declarations for C compiles (and not just C++).

Change-Id: Id0932165e71d81da5fce77a684f40c2263f58e61
This commit is contained in:
Sreeram Ramachandran 2014-05-18 15:18:36 -07:00
parent 6c83305c9a
commit 72c53933f8
5 changed files with 22 additions and 13 deletions

View File

@ -18,11 +18,11 @@
#error NetdClient.cpp should NOT be included in static libc builds.
#endif
#include <private/NetdClient.h>
#include <private/libc_logging.h>
#include <pthread.h>
#include "private/libc_logging.h"
#include "private/NetdClientDispatch.h"
#include <dlfcn.h>
#include <pthread.h>
template <typename FunctionType>
static void netdClientInitFunction(void* handle, const char* symbol, FunctionType* function) {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include <private/NetdClient.h>
#include "private/NetdClientDispatch.h"
#ifdef __i386__
#define __socketcall __attribute__((__cdecl__))
@ -25,7 +25,9 @@
extern "C" __socketcall int __accept(int, sockaddr*, socklen_t*);
extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
// This structure is modified only at startup (when libc.so is loaded) and never
// afterwards, so it's okay that it's read later at runtime without a lock.
__LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
__accept,
__connect,
};

View File

@ -14,7 +14,8 @@
* limitations under the License.
*/
#include <private/NetdClient.h>
#include "private/NetdClientDispatch.h"
#include <sys/socket.h>
int accept(int sockfd, sockaddr* addr, socklen_t* addrlen) {

View File

@ -14,7 +14,8 @@
* limitations under the License.
*/
#include <private/NetdClient.h>
#include "private/NetdClientDispatch.h"
#include <sys/socket.h>
int connect(int sockfd, const sockaddr* addr, socklen_t addrlen) {

View File

@ -14,16 +14,21 @@
* limitations under the License.
*/
#ifndef PRIVATE_NETD_CLIENT_H
#define PRIVATE_NETD_CLIENT_H
#ifndef PRIVATE_NETD_CLIENT_DISPATCH_H
#define PRIVATE_NETD_CLIENT_DISPATCH_H
#include <sys/cdefs.h>
#include <sys/socket.h>
__BEGIN_DECLS
struct NetdClientDispatch {
int (*accept)(int, sockaddr*, socklen_t*);
int (*connect)(int, const sockaddr*, socklen_t);
int (*accept)(int, struct sockaddr*, socklen_t*);
int (*connect)(int, const struct sockaddr*, socklen_t);
};
extern NetdClientDispatch __netdClientDispatch;
extern __LIBC_HIDDEN__ struct NetdClientDispatch __netdClientDispatch;
#endif // PRIVATE_NETD_CLIENT_H
__END_DECLS
#endif // PRIVATE_NETD_CLIENT_DISPATCH_H