Ejemplo n.º 1
0
/*****************************************************************************************   
 函数名称: dpd_timeout
 功能描述: dpd超时处理,删除连接
 输入参数: st
 输出参数: 无
 返 回 值: 无
-------------------------------------------------------------------------------------------    
 最近一次修改记录 :    
 修改作者: 王之云  
 修改目的: 超时处理  
 修改日期: 2012年3月20日
********************************************************************************************/  	 
void dpd_timeout(struct state *st)
{
    int action;
    struct ike_conn *c = st->st_connection;
    action = st->st_connection->dpd_action;
	so_serial_t newest = c->newest_isakmp_sa ;
	char buf_remoteip[20] = {0};
	st->st_dpd_timeout_flag = 1;
	addrtot(&st->st_remoteaddr, 0, buf_remoteip, sizeof(buf_remoteip));
	passert(IS_ISAKMP_SA_ESTABLISHED(st->st_state));
	
    passert(action == DPD_ACTION_HOLD
		    || action == DPD_ACTION_CLEAR
		    || action == DPD_ACTION_RESTART
		    || action == DPD_ACTION_RESTART_BY_PEER);

	
	if (newest != st->st_serialno && newest != SOS_NOBODY)
	{
		IPSEC_log(IPSEC_LOGLEVEL_WARNING, 
				  "Connection < %s > < %s > old state DPD TIMEOUT, "
				  "We will delete state depend on it.!", 
				  st->st_connection->name, buf_remoteip); 
		
		ipsec_release_state_by_parent(st);
		
		delete_state(st); 
		return;
	}

   {
       IPSEC_log(IPSEC_LOGLEVEL_WARNING, 
	   	         "Connection < %s > < %s > DPD TIMEOUT, we will %s connection!", 
	   	         st->st_connection->name, buf_remoteip, action == DPD_ACTION_CLEAR ? "clear":"restart");	
   }

    switch(action) 
	{
	    case DPD_ACTION_CLEAR:
			release_connection(&c);
		break;
		
	    case DPD_ACTION_RESTART:
			release_connection(&c);
			if(NULL != c)
			{
				start_initiate_connnection(c);
			}
		break;
		
	    case DPD_ACTION_HOLD:
		case DPD_ACTION_RESTART_BY_PEER:
			/*未用到此两种情况*/
		break;
		
		default :
			break;
    }
}
Ejemplo n.º 2
0
/* {{{ proto void Riak\Bucket->getKeyStream(Riak\Output\KeyStreamOutput streamer [, int $timeout = 0])
Streams all keys in the bucket */
PHP_METHOD(RiakBucket, getKeyStream)
{
    struct riak_stream_key_cb_param cb_params;
    riack_string rsbucket, *rstype;
    riak_connection *connection, *stream_connection;
    zval* zstreamer;
    long timeout;
    int riackstatus;
    timeout = 0;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zstreamer, riak_key_streamer_ce, &timeout) == FAILURE) {
        zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC);
        return;
    }
    // Create a new connection only for this stream
    // LibRiack can only handle one operation at the time pr connection
    connection = get_riak_connection(getThis() TSRMLS_CC);

    THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection);

    stream_connection = take_connection(connection->client->host, strlen(connection->client->host), connection->client->port TSRMLS_CC);
    if (!stream_connection) {
        CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(stream_connection, RIACK_ERROR_COMMUNICATION);
    }
    rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC);
#ifdef ZTS
    cb_params.tsrm_ls = TSRMLS_C;
#endif
    cb_params.zstreamer = zstreamer;
    rstype = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC);
    // Not gonna do a retry here on purpose... no reason to retry a mistake in the first place
    riackstatus = riack_stream_keys_ext(stream_connection->client, &rsbucket, rstype, riak_stream_key_cb, &cb_params, timeout);
    CHECK_RIACK_STATUS_THROW_ON_ERROR(stream_connection, riackstatus);
    RFREE(connection->client, rstype);
    release_connection(stream_connection TSRMLS_CC);
}
Ejemplo n.º 3
0
void handle_terminated_fork_client(fd_set *rdset) {
    int i, ret;
    char buf[2];

    for (i = 0; i < MAX_FDS; i++) {
        if (connection_info[i].pid && connection_info[i].fd >= 0 &&
                FD_ISSET(connection_info[i].fd, rdset)) {
            ret = read(connection_info[i].fd, buf, sizeof(buf));
            if (ret == 0 || (ret == -1 && errno == ECONNRESET)) {
                close(connection_info[i].fd);
                release_connection(i);
            } else {
                fprintf(stderr, "Unexpected read on fork-server connection: %d(%s)\n", ret, strerror(errno));
                close(connection_info[i].fd);
                release_connection(i);
            }
        }
    }
}
Ejemplo n.º 4
0
int mpi2bsp(char* input, void* input_data, int in_length, void* output, int out_length, int binary) {
  int sockfd = get_connection(POOL, "127.0.0.1", LOCAL_PORT);
  if (sockfd < 0) {
    printf("Failed to open a socket to the parent process\n");
    exit(1);
  }
  send(sockfd, input, strlen(input), 0);
  if (in_length > 0) {
    send(sockfd, input_data, in_length, 0);
  }

  int bytes_read = 0;
  if (binary) {
    char temp[4];
    while (bytes_read < 4) {
      int ret = recv(sockfd, &temp[bytes_read], 4 - bytes_read, 0);
      if (ret <= 0) {
	exit(1);
      } else {
	bytes_read += ret;
      }
    }

    int* actual_length = (int*) &temp;
    bytes_read = 0;
    while (bytes_read < *actual_length) {
      int ret = recv(sockfd, output + bytes_read, *actual_length - bytes_read, 0);
      if (ret <= 0) {
	exit(1);
      } else {
	bytes_read += ret;
      }
    }

  } else {
    while (bytes_read < out_length) {
      int ret = recv(sockfd, output + bytes_read, out_length - bytes_read, 0);
      if (ret <= 0) {
	exit(1);
      } else {
	bytes_read += ret;
	char* char_output = (char*) output;
	if (char_output[bytes_read - 1] == 0) {
	  break;
	}
      }
    }
    
  }

  release_connection(POOL, "127.0.0.1", LOCAL_PORT, sockfd);
  return bytes_read;
}
Ejemplo n.º 5
0
static int mapistore_namedprops_mysql_destructor(struct namedprops_context *self)
{
	DEBUG(5, ("[%s:%d] Destroying namedprops mysql context\n", __FUNCTION__, __LINE__));
	if (self && self->data) {
		MYSQL *conn = self->data;
		release_connection(conn);
	} else {
		DEBUG(0, ("[%s:%d] Error: tried to destroy corrupted namedprops mysql context\n",
			  __FUNCTION__, __LINE__));
	}
	return 0;
}
Ejemplo n.º 6
0
void reap_children()
{
    int status;
    int pid;
    int id;
    while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
        id = find_connection(pid);
        if (id < 0)
            continue;
        release_connection(id);
    }
    child_exited = 0;
}
Ejemplo n.º 7
0
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype type, MPI_Op op, int root, MPI_Comm comm) {
  if (!INITIALIZED) {
    exit(1);
  }

  char input[128];
  char output[8];
  int size = count * mpi_sizeof(type);
  if (MPI_RANK != root) {
    sprintf(input, "MPI_Reduce\ncount=%d\nsource=%d\ndest=%d\ncomm=%d\ntype=%d\n\n", size, root, root, comm, type);
    mpi2bsp(input, sendbuf, size, output, 8, FALSE);
  } else {
    if (sendbuf == recvbuf) {
      exit(1);
    } else if (sendbuf != MPI_IN_PLACE) {
      memcpy(recvbuf, sendbuf, size);
    }

    sprintf(input, "MPI_Reduce\nrcount=%d\nsource=%d\ncomm=%d\ntype=%d\n\n", size, root, comm, type);
    int sockfd = get_connection(POOL, "127.0.0.1", LOCAL_PORT);
    if (sockfd < 0) {
      printf("Failed to open a socket to the parent process\n");
      exit(1);
    }
    send(sockfd, input, strlen(input), 0);
    
    int i;
    void* temp = malloc(size);
    for (i = 0; i < MPI_SIZE - 1; i++) {
      int bytes_read = 0;
      while (bytes_read < size) {
	int ret = recv(sockfd, temp + bytes_read, size - bytes_read, 0);
	if (ret <= 0) {
	  exit(1);
	} else {
	  bytes_read += ret;
	}
      }
      mpi_reduce(recvbuf, temp, count, type, op);
    }
    release_connection(POOL, "127.0.0.1", LOCAL_PORT, sockfd);
    free(temp);
  }
  return 0;
}
Ejemplo n.º 8
0
static int redirect(struct connection *conn, int status)
{
	char *p = strstr(conn->buf, "Location:");
	if (p) {
		char *e;

		for (p += 9; isspace(*p); ++p)
			;
		e = strchr(p, '\n');
		if (e) {
			while (isspace(*(e - 1)))
				--e;
			*e = '\0';
			if (!conn->redirect_ok || verbose > 1)
				printf("WARNING: %s redirected to %s\n",
				       conn->url, p);
			release_connection(conn);
			free(conn->url);

			if (is_http(p))
				conn->url = strdup(p);
			else { /* Relative URL */
				int len = strlen(conn->host) + strlen(p) + 2;
				conn->url = malloc(len);
				if (conn->url)
					sprintf(conn->url, "%s/%s", conn->host, p);
			}

			if (!conn->url) {
				printf("Out of memory\n");
				return 1;
			}

			/* This will cause a bogus Multiple
			 * Closes error if it fails. */
			if (build_request(conn))
				return fail_redirect(conn);

			return 0;
		}
	}

	printf("%s: %d with no new location\n", conn->host, status);
	return status;
}
Ejemplo n.º 9
0
int MPI_Send(void* buffer, int count, MPI_Datatype type, int dest, int tag, MPI_Comm comm) {
  if (!INITIALIZED) {
    return -1;
  }

  char input[128];
  int size = count * mpi_sizeof(type);
  if (dest >= MPI_SIZE || dest == MPI_RANK) {
    printf("Illegal destination ID: %d\n", dest);
    exit(1);
  }

  struct connection_info* info = CONNECTION_INFO + dest;
  int sockfd = get_connection(POOL, info->host, info->port);
  if (sockfd < 0) {
    printf("Failed to open a socket to remote process\n");
    exit(1);
  }

  sprintf(input, "MPI_Send\ncount=%d\nsource=%d\ndest=%d\ntag=%d\ncomm=%d\ntype=%d\n\n", size, MPI_RANK, dest, tag, comm, type);
  send(sockfd, input, strlen(input), 0);
  send(sockfd, buffer, size, 0);

  int bytes_read = 0;
  char output[8];
  while (bytes_read < 8) {
    int ret = recv(sockfd, &output[bytes_read], 8 - bytes_read, 0);
    if (ret <= 0) {
      exit(1);
    } else {
      bytes_read += ret;
      char* char_output = (char*) output;
      if (char_output[bytes_read - 1] == 0) {
	break;
      }
    }
  }

  release_connection(POOL, info->host, info->port, sockfd);
  return 0; 
}
Ejemplo n.º 10
0
int build_request(struct connection *conn)
{
	char *url, *host, *p;

	url = is_http(conn->url);
	if (!url) {
#ifdef WANT_SSL
		printf("Only http/https supported\n");
#else
		printf("Only http supported\n");
#endif
		return 1;
	}

	p = strchr(url, '/');
	if (p) {
		*p = '\0';
		host = strdup(url);
		*p = '/';
		url = p;
	} else {
		host = strdup(url);
		url = "/";
	}

	if (!host) {
		printf("Out of memory\n");
		return 1;
	}

#ifdef REUSE_SOCKET
	if (CONN_OPEN) {
		if (hostcmp(conn->host, host)) {
			if (verbose)
				printf("New connection for %s\n", host);
			release_connection(conn);
		} else if (verbose)
			printf("Reuse connection for %s\n", conn->host);
	}
#endif

	if (!get_buf(conn)) {
		free(host);
		return 1;
	}

	if (!CONN_OPEN)
		if (open_socket(conn, host)) {
			printf("Connection failed to %s\n", host);
			free(host);
			free_buf(conn);
			return 1;
		}

	if (proxy)
		snprintf(conn->buf, BUFSIZE, "%s http://%s/%s %s\r\n",
				method, host, url, http);
	else if (strchr(url, ' ')) {
		/* Some sites cannot handle spaces in the url. */
		int n = sprintf(conn->buf, "%s ", method);
		char *in = url, *out = conn->buf + n;
		while (*in)
			if (*in == ' ') {
				*out++ = '%';
				*out++ = '2';
				*out++ = '0';
				++in;
			} else
				*out++ = *in++;
		sprintf(out, " %s\r\n", http);
	} else
		snprintf(conn->buf, BUFSIZE, "%s %s %s\r\n", method, url, http);

	add_full_header(conn, host);

	free(host);

	if (verbose > 1)
		printf("%s %s", proxy ? ">P" : ">", conn->buf);

	if (conn->referer)
		sprintf(conn->buf + strlen(conn->buf),
			"Referer: %.200s\r\n", conn->referer);

	strcat(conn->buf, "\r\n");

	conn->curp = conn->buf;
	conn->length = strlen(conn->buf);

	return 0;
}