Exemple #1
0
void *callback_thread(void *ctx)
{
  WSDualHttpBinding_USCOREICalculatorDuplexService *callback = (WSDualHttpBinding_USCOREICalculatorDuplexService*)ctx;
  THREAD_DETACH(THREAD_ID);

  /* chain the WSRM operations after callback operations */
  if (soap_begin_serve(callback->soap) == SOAP_OK)
    if (callback->dispatch() == SOAP_NO_METHOD)
      soap_serve_request(callback->soap);
  if (callback->soap->error)
    soap_send_fault(callback->soap);

  if (callback->soap->error != SOAP_STOP && callback->soap->error != SOAP_EOF)
    callback->soap_stream_fault(std::cerr);
  else if (callback->soap->error != SOAP_EOF || callback->soap->errnum)
    soap_wsrm_dump(callback->soap, stdout);

  callback->destroy();
  delete callback;

  return NULL;
}
Exemple #2
0
void *
tcsd_thread_run(void *v)
{
	struct tcsd_thread_data *data = (struct tcsd_thread_data *)v;
	BYTE buffer[TCSD_TXBUF_SIZE];
	struct tcsd_packet_hdr *ret_buf = NULL;
	TSS_RESULT result;
	int sizeToSend, sent_total, sent;
	UINT64 offset;
#ifndef TCSD_SINGLE_THREAD_DEBUG
	int rc;

	thread_signal_init();
#endif

	if ((data->buf_size = recv(data->sock, buffer, TCSD_TXBUF_SIZE, 0)) < 0) {
		LogError("Failed Receive: %s", strerror(errno));
		goto done;
	}
	LogDebug("Rx'd packet");

	data->buf = buffer;

	while (1) {
		sent_total = 0;
		if (data->buf_size > TCSD_TXBUF_SIZE) {
			LogError("Packet received from socket %d was too large (%u bytes)",
				 data->sock, data->buf_size);
			goto done;
		} else if (data->buf_size < (int)((2 * sizeof(UINT32)) + sizeof(UINT16))) {
			LogError("Packet received from socket %d was too small (%u bytes)",
				 data->sock, data->buf_size);
			goto done;
		}

		if ((result = getTCSDPacket(data, &ret_buf)) != TSS_SUCCESS) {
			/* something internal to the TCSD went wrong in preparing the packet
			 * to return to the TSP.  Use our already allocated buffer to return a
			 * TSS_E_INTERNAL_ERROR return code to the TSP. In the non-error path,
			 * these LoadBlob's are done in getTCSDPacket().
			 */
			offset = 0;
			/* load result */
			LoadBlob_UINT32(&offset, result, buffer);
			/* load packet size */
			LoadBlob_UINT32(&offset, sizeof(struct tcsd_packet_hdr), buffer);
			/* load num parms */
			LoadBlob_UINT16(&offset, 0, buffer);

			sizeToSend = sizeof(struct tcsd_packet_hdr);
			LogDebug("Sending 0x%X bytes back", sizeToSend);

			while (sent_total < sizeToSend) {
				if ((sent = send(data->sock,
						 &data->buf[sent_total],
						 sizeToSend - sent_total, 0)) < 0) {
					LogError("Packet send to TSP failed: send: %s. Thread exiting.",
							strerror(errno));
					goto done;
				}
				sent_total += sent;
			}
		} else {
			sizeToSend = Decode_UINT32((BYTE *)&(ret_buf->packet_size));

			LogDebug("Sending 0x%X bytes back", sizeToSend);

			while (sent_total < sizeToSend) {
				if ((sent = send(data->sock,
						 &(((BYTE *)ret_buf)[sent_total]),
						 sizeToSend - sent_total, 0)) < 0) {
					LogError("response to TSP failed: send: %s. Thread exiting.",
							strerror(errno));
					free(ret_buf);
					ret_buf = NULL;
					goto done;
				}
				sent_total += sent;
			}
			free(ret_buf);
			ret_buf = NULL;
		}

		if (tm->shutdown) {
			LogDebug("Thread %zd exiting via shutdown signal!", THREAD_ID);
			break;
		}

		/* receive the next packet */
		if ((data->buf_size = recv(data->sock, buffer, TCSD_TXBUF_SIZE, 0)) < 0) {
			LogError("TSP has closed its connection: %s. Thread exiting.",
				 strerror(errno));
			break;
		} else if (data->buf_size == 0) {
			LogDebug("The TSP has closed the socket's connection. Thread exiting.");
			break;
		}
	}

done:
	/* Closing connection to TSP */
	close(data->sock);
	data->sock = -1;
	data->buf = NULL;
	data->buf_size = -1;
	/* If the connection was not shut down cleanly, free TCS resources here */
	if (data->context != NULL_TCS_HANDLE) {
		TCS_CloseContext_Internal(data->context);
		data->context = NULL_TCS_HANDLE;
	}

#ifndef TCSD_SINGLE_THREAD_DEBUG
	MUTEX_LOCK(tm->lock);
	tm->num_active_threads--;
	/* if we're not in shutdown mode, then nobody is waiting to join this thread, so
	 * detach it so that its resources are free at THREAD_EXIT() time. */
	if (!tm->shutdown) {
		if ((rc = THREAD_DETACH(*(data->thread_id)))) {
			LogError("Thread detach failed (errno %d)."
				 " Resources may not be properly released.", rc);
		}
	}
	free(data->hostname);
	data->hostname = NULL;
	data->thread_id = THREAD_NULL;
	MUTEX_UNLOCK(tm->lock);
	THREAD_EXIT(NULL);
#else
	return NULL;
#endif
}