Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ingo Voss
OpenLDAP
Commits
5085d1f8
Commit
5085d1f8
authored
Oct 13, 2005
by
Kurt Zeilenga
Browse files
cleanup
parent
d6562f19
Changes
2
Hide whitespace changes
Inline
Side-by-side
servers/slapd/connection.c
View file @
5085d1f8
...
...
@@ -50,18 +50,22 @@ static ldap_pvt_thread_mutex_t* connections_mutex;
static
Connection
**
connections
=
NULL
;
/* set to the number of processors */
#define NUM_CONNECTION_ARRAY
2
#
define NUM_CONNECTION_ARRAY
4
/* partition the array in a modulo manner */
#define MCA_conn_array_id( fd ) ((int)fd%NUM_CONNECTION_ARRAY)
#define MCA_conn_array_element_id( fd ) ((int)fd/NUM_CONNECTION_ARRAY)
# define MCA_conn_array_id(fd) ((int)(fd)%NUM_CONNECTION_ARRAY)
# define MCA_conn_array_element_id(fd) ((int)(fd)/NUM_CONNECTION_ARRAY)
# define MCA_GET_CONNECTION(fd) (&(connections[MCA_conn_array_id(fd)])\
[MCA_conn_array_element_id(fd)])
# define MCA_GET_CONN_MUTEX(fd) (&connections_mutex[MCA_conn_array_id(fd)])
#define MCA_GET_CONNECTION(fd) &(connections[MCA_conn_array_id(fd)])[MCA_conn_array_element_id( fd )]
#define MCA_GET_CONN_MUTEX(fd) &connections_mutex[MCA_conn_array_id(fd)]
#else
/* protected by connections_mutex */
static
ldap_pvt_thread_mutex_t
connections_mutex
;
static
Connection
*
connections
=
NULL
;
# define MCA_GET_CONNECTION(fd) (&connections[s])
# define MCA_GET_CONN_MUTEX(fd) (&connections_mutex)
#endif
static
ldap_pvt_thread_mutex_t
conn_nextid_mutex
;
...
...
@@ -414,11 +418,7 @@ static Connection* connection_get( ber_socket_t s )
}
#ifndef HAVE_WINSOCK
#ifdef SLAP_MULTI_CONN_ARRAY
c
=
MCA_GET_CONNECTION
(
s
);
#else
c
=
&
connections
[
s
];
#endif
assert
(
c
->
c_struct_state
!=
SLAP_C_UNINITIALIZED
);
...
...
@@ -534,19 +534,10 @@ long connection_init(
assert
(
s
<
dtblsize
);
#endif
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_lock
(
&
connections_mutex
);
#endif
#ifndef HAVE_WINSOCK
#ifdef SLAP_MULTI_CONN_ARRAY
c
=
MCA_GET_CONNECTION
(
s
);
#else
c
=
&
connections
[
s
];
#endif
#else
{
ber_socket_t
i
;
...
...
@@ -672,11 +663,7 @@ long connection_init(
c
->
c_close_reason
=
"?"
;
/* should never be needed */
ber_sockbuf_ctrl
(
c
->
c_sb
,
LBER_SB_OPT_SET_FD
,
&
s
);
ldap_pvt_thread_mutex_unlock
(
&
c
->
c_mutex
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
@@ -764,11 +751,7 @@ long connection_init(
slap_sasl_external
(
c
,
ssf
,
authid
);
ldap_pvt_thread_mutex_unlock
(
&
c
->
c_mutex
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
backend_connection_init
(
c
);
...
...
@@ -1490,11 +1473,7 @@ int connection_read(ber_socket_t s)
assert
(
connections
!=
NULL
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_lock
(
&
connections_mutex
);
#endif
/* get (locked) connection */
c
=
connection_get
(
s
);
...
...
@@ -1505,11 +1484,7 @@ int connection_read(ber_socket_t s)
(
long
)
s
,
0
,
0
);
slapd_remove
(
s
,
1
,
0
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
-
1
;
}
...
...
@@ -1520,11 +1495,7 @@ int connection_read(ber_socket_t s)
"connection_read(%d): closing, ignoring input for id=%lu
\n
"
,
s
,
c
->
c_connid
,
0
);
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume
(
s
);
...
...
@@ -1541,11 +1512,7 @@ int connection_read(ber_socket_t s)
c
->
c_clientfunc
,
c
->
c_clientarg
);
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
@@ -1619,11 +1586,7 @@ int connection_read(ber_socket_t s)
!
ber_sockbuf_ctrl
(
c
->
c_sb
,
LBER_SB_OPT_DATA_READY
,
NULL
)
)
{
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume
(
s
);
...
...
@@ -1638,11 +1601,7 @@ int connection_read(ber_socket_t s)
/* If previous layer is not removed yet, give up for now */
if
(
!
c
->
c_sasl_sockctx
)
{
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume
(
s
);
...
...
@@ -1665,11 +1624,7 @@ int connection_read(ber_socket_t s)
connection_closing
(
c
,
"SASL layer install failure"
);
connection_close
(
c
);
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
}
...
...
@@ -1713,11 +1668,7 @@ int connection_read(ber_socket_t s)
connection_closing
(
c
,
conn_lost_str
);
connection_close
(
c
);
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
@@ -1734,11 +1685,7 @@ int connection_read(ber_socket_t s)
}
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
@@ -1978,11 +1925,7 @@ connection_resched( Connection *conn )
ber_sockbuf_ctrl
(
conn
->
c_sb
,
LBER_SB_OPT_GET_FD
,
&
sd
);
/* use trylock to avoid possible deadlock */
#ifdef SLAP_MULTI_CONN_ARRAY
rc
=
ldap_pvt_thread_mutex_trylock
(
MCA_GET_CONN_MUTEX
(
sd
)
);
#else
rc
=
ldap_pvt_thread_mutex_trylock
(
&
connections_mutex
);
#endif
if
(
rc
)
{
Debug
(
LDAP_DEBUG_TRACE
,
...
...
@@ -1994,11 +1937,7 @@ connection_resched( Connection *conn )
* so recheck state below.
*/
ldap_pvt_thread_mutex_unlock
(
&
conn
->
c_mutex
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock
(
MCA_GET_CONN_MUTEX
(
sd
)
);
#else
ldap_pvt_thread_mutex_lock
(
&
connections_mutex
);
#endif
ldap_pvt_thread_mutex_lock
(
&
conn
->
c_mutex
);
}
...
...
@@ -2013,11 +1952,7 @@ connection_resched( Connection *conn )
connection_close
(
conn
);
}
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
sd
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
@@ -2127,11 +2062,7 @@ int connection_write(ber_socket_t s)
assert
(
connections
!=
NULL
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_lock
(
&
connections_mutex
);
#endif
c
=
connection_get
(
s
);
if
(
c
==
NULL
)
{
...
...
@@ -2139,11 +2070,7 @@ int connection_write(ber_socket_t s)
"connection_write(%ld): no connection!
\n
"
,
(
long
)
s
,
0
,
0
);
slapd_remove
(
s
,
1
,
0
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
-
1
;
}
...
...
@@ -2184,11 +2111,7 @@ int connection_write(ber_socket_t s)
}
connection_return
(
c
);
#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock
(
MCA_GET_CONN_MUTEX
(
s
)
);
#else
ldap_pvt_thread_mutex_unlock
(
&
connections_mutex
);
#endif
return
0
;
}
...
...
servers/slapd/daemon.c
View file @
5085d1f8
...
...
@@ -98,20 +98,16 @@ static struct slap_daemon {
ber_socket_t
sd_nactives
;
int
sd_nwriters
;
#ifdef SLAP_LIGHTWEIGHT_LISTENER
/*
* 0: reading on a FD is suspended
* 1: reading on a FD is allowed
*/
int
*
sd_suspend
;
#endif
#ifdef HAVE_EPOLL
struct
epoll_event
*
sd_epolls
;
int
sd_nepolls
;
int
*
sd_index
;
int
sd_epfd
;
int
sd_nfds
;
# ifdef SLAP_LIGHTWEIGHT_LISTENER
int
*
sd_suspend
;
/* 0: suspended, 1: not suspended */
# endif
#else
#ifndef HAVE_WINSOCK
/* In winsock, accept() returns values higher than dtblsize
...
...
@@ -121,6 +117,9 @@ static struct slap_daemon {
fd_set
sd_actives
;
fd_set
sd_readers
;
fd_set
sd_writers
;
# ifdef SLAP_LIGHTWEIGHT_LISTENER
fd_set
sd_suspend
;
/* unset: suspended, set: not suspended */
# endif
#endif
}
slap_daemon
;
...
...
@@ -300,10 +299,9 @@ static struct slap_daemon {
# ifdef SLAP_LIGHTWEIGHT_LISTENER
# define SLAP_SOCK_SET_INIT do { \
CHK_SETSIZE; \
slap_daemon.sd_suspend = ch_malloc(sizeof(int) * dtblsize); \
for (i=0; i<dtblsize; i++) slap_daemon.sd_suspend[i] = 0; \
FD_ZERO(&slap_daemon.sd_readers); \
FD_ZERO(&slap_daemon.sd_writers); \
FD_ZERO(&slap_daemon.sd_suspend); \
} while (0)
# else
# define SLAP_SOCK_SET_INIT do { \
...
...
@@ -321,9 +319,9 @@ static struct slap_daemon {
!SLAP_SOCK_IS_READ(fd) && !SLAP_SOCK_IS_WRITE(fd))
# ifdef SLAP_LIGHTWEIGHT_LISTENER
# define SLAP_SOCK_SET_SUSPEND(s)
(
slap_daemon.sd_suspend
[(s)] = 1
)
# define SLAP_SOCK_CLR_SUSPEND(s)
(
slap_daemon.sd_suspend
[(s)] = 0
)
# define SLAP_SOCK_IS_SUSPEND(s)
(
slap_daemon.sd_suspend
[(s)] == 1
)
# define SLAP_SOCK_SET_SUSPEND(s)
FD_SET((s), &
slap_daemon.sd_suspend)
# define SLAP_SOCK_CLR_SUSPEND(s)
FD_CLR((s), &
slap_daemon.sd_suspend)
# define SLAP_SOCK_IS_SUSPEND(s)
FD_ISSET((s), &
slap_daemon.sd_suspend)
# endif
# ifdef HAVE_WINSOCK
...
...
@@ -1945,12 +1943,8 @@ slapd_daemon_task(
int
rc
;
if
(
ns
<=
0
)
break
;
if
(
slap_listeners
[
l
]
->
sl_sd
==
AC_SOCKET_INVALID
)
continue
;
if
(
!
SLAP_EVENT_IS_READ
(
slap_listeners
[
l
]
->
sl_sd
))
continue
;
if
(
slap_listeners
[
l
]
->
sl_sd
==
AC_SOCKET_INVALID
)
continue
;
if
(
!
SLAP_EVENT_IS_READ
(
slap_listeners
[
l
]
->
sl_sd
))
continue
;
#ifdef SLAP_LIGHTWEIGHT_LISTENER
...
...
@@ -2116,13 +2110,15 @@ slapd_daemon_task(
if
(
SLAP_EVENT_IS_LISTENER
(
i
)
#ifdef LDAP_CONNECTIONLESS
&&
!
((
SLAP_EVENT_LISTENER
(
i
))
->
sl_is_udp
)
&&
!
((
SLAP_EVENT_LISTENER
(
i
))
->
sl_is_udp
)
#endif
)
continue
;
)
{
continue
;
}
/* Don't log internal wake events */
if
(
SLAP_EVENT_FD
(
i
)
==
wake_sds
[
0
]
)
continue
;
if
(
SLAP_EVENT_FD
(
i
)
==
wake_sds
[
0
]
)
continue
;
r
=
SLAP_EVENT_IS_READ
(
i
);
w
=
SLAP_EVENT_IS_WRITE
(
i
);
...
...
@@ -2138,7 +2134,7 @@ slapd_daemon_task(
if
(
SLAP_EVENT_IS_LISTENER
(
i
)
)
{
#ifdef SLAP_LIGHTWEIGHT_LISTENER
rc
=
new_connection_activate
(
SLAP_EVENT_LISTENER
(
i
));
rc
=
new_connection_activate
(
SLAP_EVENT_LISTENER
(
i
));
#else
rc
=
slapd_handle_listener
(
SLAP_EVENT_LISTENER
(
i
));
#endif
...
...
@@ -2151,8 +2147,7 @@ slapd_daemon_task(
fd
=
SLAP_EVENT_FD
(
i
);
/* Ignore wake events, they were handled above */
if
(
fd
==
wake_sds
[
0
]
)
continue
;
if
(
fd
==
wake_sds
[
0
]
)
continue
;
if
(
SLAP_EVENT_IS_WRITE
(
i
)
)
{
Debug
(
LDAP_DEBUG_CONNS
,
...
...
@@ -2186,9 +2181,7 @@ slapd_daemon_task(
connection_processing_activate
(
fd
);
}
#else
if
(
connection_read
(
fd
)
<
0
)
{
slapd_close
(
fd
);
}
if
(
connection_read
(
fd
)
<
0
)
slapd_close
(
fd
);
#endif
}
}
...
...
@@ -2221,9 +2214,7 @@ slapd_daemon_task(
0
,
0
,
0
);
}
if
(
slapd_gentle_shutdown
!=
2
)
{
close_listeners
(
0
);
}
if
(
slapd_gentle_shutdown
!=
2
)
close_listeners
(
0
);
if
(
!
slapd_gentle_shutdown
)
{
slapd_abrupt_shutdown
=
1
;
...
...
@@ -2309,10 +2300,9 @@ static int sockinit(void)
/* The WinSock DLL is acceptable. Proceed. */
#elif defined( HAVE_WINSOCK )
WSADATA
wsaData
;
if
(
WSAStartup
(
0x0101
,
&
wsaData
)
!=
0
)
{
return
-
1
;
}
if
(
WSAStartup
(
0x0101
,
&
wsaData
)
!=
0
)
return
-
1
;
#endif
return
0
;
}
...
...
@@ -2325,7 +2315,8 @@ static int sockdestroy(void)
}
RETSIGTYPE
slap_sig_shutdown
(
int
sig
)
{
slap_sig_shutdown
(
int
sig
)
{
#if 0
Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment