1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
42
#include "cl_commlib.h"
44
#include "uti/sge_profiling.h"
46
/* shutdown when test client can't connect for more than 15 min */
47
#define SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT 15*60
48
#define DATA_SIZE 5000
49
#define PACKAGE_COUNTER
52
static int rcv_messages = 0;
53
static int snd_messages = 0;
55
void sighandler_client(int sig);
56
static int do_shutdown = 0;
58
static cl_com_handle_t* handle = NULL;
60
void sighandler_client(
63
/* thread_signal_receiver = pthread_self(); */
71
printf("do_shutdown\n");
72
/* shutdown all sockets */
79
#ifdef __CL_FUNCTION__
80
#undef __CL_FUNCTION__
82
#define __CL_FUNCTION__ "main()"
83
extern int main(int argc, char** argv)
88
time_t shutdown_time = 0;
92
#ifndef PACKAGE_COUNTER
93
char data[DATA_SIZE] = "gdi request";
96
cl_xml_ack_type_t ack_type = CL_MIH_MAT_NAK;
97
cl_bool_t synchron = CL_FALSE;
102
printf("syntax: debug_level vmaster_port vmaster_host reconnect [no_output]\n");
107
if (strcmp(argv[5],"no_output") == 0) {
109
printf("virtual gdi client: no_output option set\n");
113
reconnect = atoi(argv[4]);
115
if (reconnect == 1) {
116
/* do all stuff synchron */
117
ack_type = CL_MIH_MAT_ACK;
121
/* setup signalhandling */
122
memset(&sa, 0, sizeof(sa));
123
sa.sa_handler = sighandler_client; /* one handler for all signals */
124
sigemptyset(&sa.sa_mask);
125
sigaction(SIGINT, &sa, NULL);
126
sigaction(SIGTERM, &sa, NULL);
127
sigaction(SIGHUP, &sa, NULL);
128
sigaction(SIGPIPE, &sa, NULL);
130
gettimeofday(&now, NULL);
131
shutdown_time = now.tv_sec + SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT;
133
printf("virtual gdi client is connecting to the virtual qmaster for each request.\n");
135
cl_com_setup_commlib(CL_NO_THREAD , (cl_log_t)atoi(argv[1]), NULL );
137
while (do_shutdown == 0) {
138
char *snd_data = NULL;
139
gettimeofday(&now, NULL);
141
if (now.tv_sec > shutdown_time ) {
142
printf("shutting down test - timeout\n");
146
cl_com_setup_commlib(CL_NO_THREAD , (cl_log_t)atoi(argv[1]), NULL);
148
handle = cl_com_create_handle(NULL, CL_CT_TCP, CL_CM_CT_MESSAGE, CL_FALSE, atoi(argv[2]), CL_TCP_DEFAULT, "virtual_gdi_client", 0, 1, 0);
149
if (handle == NULL) {
150
printf("could not get handle\n");
155
printf("local hostname is \"%s\"\n", handle->local->comp_host);
156
printf("local component is \"%s\"\n", handle->local->comp_name);
157
printf("local component id is \"%ld\"\n", handle->local->comp_id);
163
cl_com_get_connect_port(handle, &i);
164
printf("connecting to port \"%d\" on host \"%s\"\n", i, argv[3]);
168
while (do_shutdown == 0) {
170
cl_com_message_t* message = NULL;
171
cl_com_endpoint_t* sender = NULL;
172
if (snd_data == NULL) {
173
snd_data = malloc(DATA_SIZE);
174
#ifdef PACKAGE_COUNTER
175
sprintf(snd_data, "%d\n", snd_messages);
177
memcpy(snd_data, data, DATA_SIZE);
180
#ifdef PACKAGE_COUNTER
182
sprintf(snd_data, "%d\n", snd_messages);
186
gettimeofday(&now,NULL);
187
if (now.tv_sec > shutdown_time ) {
188
printf("shutting down test - timeout\n");
192
retval = cl_commlib_send_message(handle, argv[3], "virtual_master", 1,
194
(cl_byte_t**)(&snd_data), DATA_SIZE,
195
NULL, 0, 0 , CL_FALSE, synchron);
196
if (retval == CL_RETVAL_OK) {
198
retval = cl_commlib_receive_message(handle, NULL, NULL, 0, /* handle, comp_host, comp_name , comp_id, */
199
CL_TRUE, 0, /* syncron, response_mid */
201
if (retval == CL_RETVAL_OK) {
202
gettimeofday(&now,NULL);
203
shutdown_time = now.tv_sec + SGE_TEST_VIRTUAL_CLIENT_SHUTDOWN_TIMEOUT;
205
snd_data = (char*)message->message;
206
message->message = NULL;
208
#ifdef PACKAGE_COUNTER
209
if (atoi(snd_data) != rcv_messages) {
210
printf("!!!! %d. message was lost, got %s\n", rcv_messages, snd_data);
215
if (now.tv_sec != last_time && !no_output) {
216
printf("virtual gdi client message count[received |%d| / sent |%d|]...\n", rcv_messages, snd_messages);
217
last_time = now.tv_sec;
221
cl_com_free_message(&message);
222
cl_com_free_endpoint(&sender);
224
/* shutdown when virtual qmaster is not running anymore */
225
if (rcv_messages > 0) {
226
printf("cl_commlib_receive_message returned: %s\n", cl_get_error_text(retval));
229
/* we are not connected, sleep one second */
235
/* shutdown when virtual qmaster is not running anymore */
236
if (rcv_messages > 0) {
237
printf("cl_commlib_send_message returned: %s\n", cl_get_error_text(retval));
241
if (reconnect == 1) {
245
cl_commlib_shutdown_handle(handle, CL_FALSE);
247
cl_com_cleanup_commlib();
249
printf("main done\n");