mturk 2005/06/30 08:19:15
Added: jni/native/os/unix uxpipe.c
Log:
Add AF_UNIX network interface implementation.
Revision ChangesPath
1.1 jakarta-tomcat-connectors/jni/native/os/unix/uxpipe.c
Index: uxpipe.c
===
/* Copyright 2000-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** UNIX AF_LOCAL network wrapper
*
* @author Mladen Turk
* @version $Revision: 1.1 $, $Date: 2005/06/30 15:19:15 $
*/
#include tcn.h
#include apr_thread_mutex.h
#include apr_poll.h
/* ### should be tossed in favor of APR */
#include sys/stat.h
#include sys/un.h /* for sockaddr_un */
#ifdef TCN_DO_STATISTICS
#include apr_atomic.h
static volatile apr_uint32_t uxp_created = 0;
static volatile apr_uint32_t uxp_closed = 0;
static volatile apr_uint32_t uxp_cleared = 0;
static volatile apr_uint32_t uxp_accepted = 0;
void uxp_network_dump_statistics()
{
fprintf(stderr, NT Network Statistics ..\n);
fprintf(stderr, Sockets created : %d\n, uxp_created);
fprintf(stderr, Sockets accepted: %d\n, uxp_accepted);
fprintf(stderr, Sockets closed : %d\n, uxp_closed);
fprintf(stderr, Sockets cleared : %d\n, uxp_cleared);
}
#endif
#define DEFNAME /var/run/tomcatnativesock
#define DEFNAME_FMT /var/run/tomcatnativesock%08x%08x
#define DEFSIZE 8192
#define DEFTIMEOUT 6
#define TCN_UXP_UNKNOWN 0
#define TCN_UXP_CLIENT 1
#define TCN_UXP_ACCEPTED2
#define TCN_UXP_SERVER 3
#define TCN_UNIX_MAXPATH1024
typedef struct {
apr_pool_t *pool;
apr_socket_t*sock; /* APR socket */
int sd;
struct sockaddr_un uxaddr;
int timeout;
int mode; /* Client or server mode */
charname[TCN_UNIX_MAXPATH+1];
} tcn_uxp_conn_t;
static apr_status_t APR_THREAD_FUNC
uxp_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
if (t 0)
con-timeout = -1;
else
con-timeout = (int)(apr_time_as_msec(t));
return APR_SUCCESS;
}
static apr_status_t APR_THREAD_FUNC
uxp_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t*)sock;
if (con-timeout 0)
*t = -1;
else
*t = con-timeout * 1000;
return APR_SUCCESS;
}
static APR_INLINE apr_status_t APR_THREAD_FUNC
uxp_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
return apr_socket_opt_set(con-sock, opt, on);
}
static APR_INLINE apr_status_t APR_THREAD_FUNC
uxp_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
return apr_socket_opt_get(con-sock, opt, on);
}
static apr_status_t uxp_cleanup(void *data)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)data;
if (con) {
if (con-sock) {
apr_socket_close(con-sock);
con-sock = NULL;
}
if (con-mode == TCN_UXP_SERVER) {
unlink(con-name);
con-mode = TCN_UXP_UNKNOWN;
}
}
#ifdef TCN_DO_STATISTICS
apr_atomic_inc32(uxp_cleared);
#endif
return APR_SUCCESS;
}
static apr_status_t APR_THREAD_FUNC
uxp_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
return apr_socket_shutdown(con-sock, how);
}
static apr_status_t APR_THREAD_FUNC
uxp_socket_close(apr_socket_t *sock)
{
#ifdef TCN_DO_STATISTICS
apr_atomic_inc32(uxp_closed);
#endif
return uxp_cleanup(sock);
}
static apr_status_t APR_THREAD_FUNC
uxp_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
return apr_socket_recv(con-sock, buf, len);
}
static apr_status_t APR_THREAD_FUNC
uxp_socket_send(apr_socket_t *sock, const char *buf,
apr_size_t *len)
{
tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
return