<commit_before>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2006 GridWay Team, Distributed Systems Architecture         */
/* Group, Universidad Complutense de Madrid                                   */
/*                                                                            */
/* 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.                                             */
/* -------------------------------------------------------------------------- */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <time.h>

#include "gw_client.h"
#include "gw_rm_msg.h"
#include "gw_rm.h"
#include "gw_file_parser.h"

extern gw_client_t gw_client;

int  gw_client_connect();
void gw_client_disconnect(int socket);

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

gw_return_code_t gw_client_wait(int job_id, int *exit_code, signed long timeout)
{
    gw_msg_t       msg;
 	int            rc;
 	int            length;
 	struct timeval tout;
 	fd_set         socket;
	gw_msg_job_t   job_status;
	int            fd;
	 	
 	if ( gw_client.initialize == GW_FALSE )
		return GW_RC_FAILED_INIT;

	if ( timeout == 0 )
	{
		rc = gw_client_job_status(job_id, &job_status);
		
		if ( rc != GW_RC_SUCCESS )
			return rc;
			
		if ((job_status.job_state == GW_JOB_STATE_ZOMBIE) &&
		    (job_status.job_state == GW_JOB_STATE_FAILED))
		{
			*exit_code = job_status.exit_code;
		}
		
		return GW_RC_SUCCESS;		
	}
	
    /* ----------------------------------------------------------------- */
    /* 1.- Format msg     	      	      	      	      	      	     */
    /* ----------------------------------------------------------------- */
    
  	msg.msg_type  = GW_MSG_WAIT;
  	msg.wait_type = GW_MSG_WAIT_JOB;
  	msg.job_id    = job_id;
	length        = sizeof(gw_msg_t);
	  	
  	pthread_mutex_lock(&(gw_client.mutex));
  	
	strncpy(msg.owner,gw_client.owner,GW_MSG_STRING_SHORT);  	

  	pthread_mutex_unlock(&(gw_client.mutex));	
  	
    /* ----------------------------------------------------------------- */
    /* 2.- Send submit request    	      	      	      	      	     */
    /* ----------------------------------------------------------------- */

	fd = gw_client_connect();
	
	if (fd == -1)
	{
		return GW_RC_FAILED_CONNECTION;
	}

	rc = send(fd,(void *) &msg,length,0);<commit_msg>[project @ 2006-06-14 12:16:35 by ruben]<commit_after>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2006 GridWay Team, Distributed Systems Architecture         */
/* Group, Universidad Complutense de Madrid                                   */
/*                                                                            */
/* 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.                                             */
/* -------------------------------------------------------------------------- */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <time.h>

#include "gw_client.h"
#include "gw_rm_msg.h"
#include "gw_rm.h"
#include "gw_file_parser.h"

extern gw_client_t gw_client;

int  gw_client_connect();
void gw_client_disconnect(int socket);

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

gw_return_code_t gw_client_wait(int job_id, int *exit_code, signed long timeout)
{
    gw_msg_t       msg;
 	int            rc;
 	int            length;
 	struct timeval tout;
 	fd_set         socket;
	gw_msg_job_t   job_status;
	int            fd;
	 	
 	if ( gw_client.initialize == GW_FALSE )
		return GW_RC_FAILED_INIT;

	if ( timeout == 0 )
	{
		rc = gw_client_job_status(job_id, &job_status);
		
		if ( rc != GW_RC_SUCCESS )
			return rc;
			
		if ((job_status.job_state == GW_JOB_STATE_ZOMBIE) ||
		    (job_status.job_state == GW_JOB_STATE_FAILED))
		{
			*exit_code = job_status.exit_code;
			
			return GW_RC_SUCCESS;
		}
		else
			return GW_RC_FAILED_TIMEOUT;	
	}
	
    /* ----------------------------------------------------------------- */
    /* 1.- Format msg     	      	      	      	      	      	     */
    /* ----------------------------------------------------------------- */
    
  	msg.msg_type  = GW_MSG_WAIT;
  	msg.wait_type = GW_MSG_WAIT_JOB;
  	msg.job_id    = job_id;
	length        = sizeof(gw_msg_t);
	  	
  	pthread_mutex_lock(&(gw_client.mutex));
  	
	strncpy(msg.owner,gw_client.owner,GW_MSG_STRING_SHORT);  	

  	pthread_mutex_unlock(&(gw_client.mutex));	
  	
    /* ----------------------------------------------------------------- */
    /* 2.- Send submit request    	      	      	      	      	     */
    /* ----------------------------------------------------------------- */

	fd = gw_client_connect();
	
	if (fd == -1)
	{
		return GW_RC_FAILED_CONNECTION;
	}

	rc = send(fd,(void *) &msg,length,0);
{'fraction_non_alphanumeric': 0.273246448967638, 'fraction_numerical': 0.007028847561868502, 'mean_word_length': 0.9871981379109689, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '213609', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1739, 'n_words': 396}