//.........这里部分代码省略.........
else{
*(uint32_t *)snddoutcount_addr = 15;
count = 0;
i = 1;
st = 3;
}
}
else if(st == 3){
if (count < length_max){
*(uint32_t *)hash0_addr = length_alphabet[count];
*(uint32_t *)snddoutcount_addr = i;
if(i == *(uint32_t *)snddincount_addr){
printf("Length information for part %i is sent. %i. \r\n", count, length_alphabet[count]);
count = count + 1;
if(i < 14){ i = i + 1;}
else {i = 1;}
}
}
else {
*(uint32_t *)snddoutcount_addr = 0;
*(uint32_t *)hash0_addr = length_min;
if (0 == *(uint32_t *)snddincount_addr){
*(uint32_t *)snddoutcount_addr = 15;
st = 4;
count = 0;
time (&start);
printf("Done gathering information, starting. \r\n");
}
}
}
else if(st == 4){
*(uint32_t *)snddoutcount_addr = count;
if(count == *(uint32_t *)snddincount_addr){
output[count] = *(uint32_t *)result_addr;
printf("Received part %i\r\n", count);
count = count + 1;
}
if(count >= 16){
st = 5;
count = 0;
time (&end);
dif = difftime (end,start);
printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", output[15], output[14], output[13], output[12], output[11], output[10], output[9], output[8], output[7], output[6], output[5], output[4], output[3], output[2], output[1], output[0]);
}
}
else if (st == 5){
*(uint32_t *)snddoutcount_addr = count;
if(count == *(uint32_t *)snddincount_addr){
rounds[count] = *(uint32_t *)result_addr;
count = count + 1;
}
if (count == 2){
rounds64 = (uint64_t) rounds[1] << 32 | rounds[0];
printf("Number of 20 ns rounds used to find the correct hash: %g\r\n", (double)rounds64);
printf("That equals to %g seconds \r\n", (double)rounds64*0.00000002);
printf("This program measured %g seconds from confirmed hash to received result. \r\n", dif);
st = 0;
}
}
else {
printf("From the left, enter the first 8 digits of the hash: \r\n");
scanf("%x", &hash[4]);
*(uint32_t *)hash0_addr = hash[4];
*(uint32_t *)snddoutcount_addr = 4;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[3]);
*(uint32_t *)hash0_addr = hash[3];
*(uint32_t *)snddoutcount_addr = 3;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[2]);
*(uint32_t *)hash0_addr = hash[2];
*(uint32_t *)snddoutcount_addr = 2;
printf("Enter next 8 digits of the hash: \r\n");
scanf("%x", &hash[1]);
*(uint32_t *)hash0_addr = hash[1];
*(uint32_t *)snddoutcount_addr = 1;
printf("Enter last 8 digits of the hash: \r\n");
scanf("%x", &hash[0]);
*(uint32_t *)hash0_addr = hash[0];
*(uint32_t *)snddoutcount_addr = 0;
printf("%x %x %x %x %x\n", hash[4], hash[3], hash[2], hash[1], hash[0]);
st = 1;
count = 0;
*(uint32_t *)snddoutcount_addr = 10;
corr = 0;
}
}
return 0;
}
开发者ID:NilsOveT,项目名称:pipeSha1,代码行数:101,代码来源:main.c
示例4: main
//.........这里部分代码省略.........
int h=state.height;
dstImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3);
py = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1); // Y component of YUV I420 frame
pu = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // U component of YUV I420 frame
pv = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // V component of YUV I420 frame
pu_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
pv_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
image = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); // final picture to display
// create camera
if (!create_camera_component(&state))
{
vcos_log_error("%s: Failed to create camera component", __func__);
}
// AZG(20160226): Debug
else if ((status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
{
vcos_log_error("%s: Failed to create preview component", __func__);
destroy_camera_component(&state);
}
else
{
PORT_USERDATA callback_data;
camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT];
camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT];
VCOS_STATUS_T vcos_status;
callback_data.pstate = &state;
vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0);
vcos_assert(vcos_status == VCOS_SUCCESS);
// assign data to use for callback
camera_video_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data;
// init timer
time(&timer_begin);
// start capture
if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS)
{
goto error;
}
// Send all the buffers to the video port
int num = mmal_queue_length(state.video_pool->queue);
int q;
for (q=0; q<num; q++)
{
MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.video_pool->queue);
if (!buffer)
vcos_log_error("Unable to get a required buffer %d from pool queue", q);
if (mmal_port_send_buffer(camera_video_port, buffer)!= MMAL_SUCCESS)
vcos_log_error("Unable to send a buffer to encoder output port (%d)", q);
}
// Now wait until we need to stop
vcos_sleep(state.timeout);
error:
mmal_status_to_int(status);
// Disable all our ports that are not handled by connections
check_disable_port(camera_still_port);
if (state.camera_component)
mmal_component_disable(state.camera_component);
//destroy_encoder_component(&state);
// raspipreview_destroy(&state.preview_parameters);
destroy_camera_component(&state);
}
if (status != 0)
raspicamcontrol_check_configuration(128);
time(&timer_end); /* get current time; same as: timer = time(NULL) */
cvReleaseImage(&dstImage);
cvReleaseImage(&pu);
cvReleaseImage(&pv);
cvReleaseImage(&py);
cvReleaseImage(&pu_big);
cvReleaseImage(&pv_big);
secondsElapsed = difftime(timer_end,timer_begin);
printf ("%.f seconds for %d frames : FPS = %f\n", secondsElapsed,nCount,(float)((float)(nCount)/secondsElapsed));
return 0;
}
PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure, int url_encode, int httponly TSRMLS_DC)
{
char *cookie;
int len=sizeof("Set-Cookie: ");
zend_string *dt;
sapi_header_line ctr = {0};
int result;
zend_string *encoded_value = NULL;
if (name && strpbrk(name, "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie names cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
return FAILURE;
}
if (!url_encode && value && strpbrk(value, ",; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie values cannot contain any of the following ',; \\t\\r\\n\\013\\014'" );
return FAILURE;
}
len += name_len;
if (value && url_encode) {
encoded_value = php_url_encode(value, value_len);
len += encoded_value->len;
} else if (value) {
encoded_value = zend_string_init(value, value_len, 0);
len += encoded_value->len;
}
if (path) {
len += path_len;
}
if (domain) {
len += domain_len;
}
cookie = emalloc(len + 100);
if (value && value_len == 0) {
/*
* MSIE doesn't delete a cookie when you set it to a null value
* so in order to force cookies to be deleted, even on MSIE, we
* pick an expiry date in the past
*/
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, 1, 0 TSRMLS_CC);
snprintf(cookie, len + 100, "Set-Cookie: %s=deleted; expires=%s; Max-Age=0", name, dt->val);
zend_string_free(dt);
} else {
snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value->val : "");
if (expires > 0) {
const char *p;
char tsdelta[13];
strlcat(cookie, COOKIE_EXPIRES, len + 100);
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0 TSRMLS_CC);
/* check to make sure that the year does not exceed 4 digits in length */
p = zend_memrchr(dt->val, '-', dt->len);
if (!p || *(p + 5) != ' ') {
zend_string_free(dt);
efree(cookie);
zend_string_free(encoded_value);
zend_error(E_WARNING, "Expiry date cannot have a year greater than 9999");
return FAILURE;
}
strlcat(cookie, dt->val, len + 100);
zend_string_free(dt);
snprintf(tsdelta, sizeof(tsdelta), ZEND_LONG_FMT, (zend_long) difftime(expires, time(NULL)));
strlcat(cookie, COOKIE_MAX_AGE, len + 100);
strlcat(cookie, tsdelta, len + 100);
}
}
if (encoded_value) {
zend_string_free(encoded_value);
}
if (path && path_len > 0) {
strlcat(cookie, COOKIE_PATH, len + 100);
strlcat(cookie, path, len + 100);
}
if (domain && domain_len > 0) {
strlcat(cookie, COOKIE_DOMAIN, len + 100);
strlcat(cookie, domain, len + 100);
}
if (secure) {
strlcat(cookie, COOKIE_SECURE, len + 100);
}
if (httponly) {
strlcat(cookie, COOKIE_HTTPONLY, len + 100);
}
ctr.line = cookie;
ctr.line_len = strlen(cookie);
result = sapi_header_op(SAPI_HEADER_ADD, &ctr TSRMLS_CC);
efree(cookie);
return result;
}
//.........这里部分代码省略.........
/*
* Insert the temps in the grid structure with the newTemps array
* Grab the max and min temperatures
*/
for( i = 0; i < numGridBoxes; i++) {
newTemps[i] = grid[i].temp;
}
getMinMax(newTemps, numGridBoxes, &maxTemp, &minTemp);
/*
* Construct the storage box for all threads
* We will be blocking the gridboxes instead of cyclic distribution.
* For example:
* Thread 1: compute grid boxes [0 to (numGridBoxes / numThreads)]
*/
threadStorage *storage = malloc(sizeof(threadStorage) * numThreads);
{
int start;
int spacing = numGridBoxes / numThreads;
for( i = 0, start = 0; i < numThreads; i++, start += spacing ) {
storage[i].id = i;
storage[i].newTemps = &newTemps[start];
storage[i].grid = &grid[start];
storage[i].numGridBoxes = numGridBoxes / numThreads;
}
// Very last thread must pick up the remainder if numGridBoxes/numThreads is not an even integer
storage[numThreads - 1].numGridBoxes += numGridBoxes - (spacing * numThreads);
}
/*
* Time to do the math.
* Compute the AMR Dissipation to convergence
*/
time(&startTime);
clockTime = clock();
while( (maxTemp - minTemp) > (epsilon * maxTemp) ) {
iter++;
/*
* Spawn off all threads
*/
for( i = 0; i < numThreads; i++){
int errno = pthread_create(&threads[i], NULL, threadEntry, &storage[i]);
if( errno ) {
fprintf(stdout, "Iteration %5d | Error creating thread %3d| ERROR: %5d\n", iter, i, errno);
}
}
/*
* Join all threads
*/
for( i = 0; i < numThreads; i++){
int errno = pthread_join(threads[i], NULL);
if( errno ) {
fprintf(stdout, "Iteration %5d | Error joining thread %3d| ERROR: %5d\n", iter, i, errno);
}
}
// Grab the max and min temperatures
getMinMax(newTemps, numGridBoxes, &maxTemp, &minTemp);
// Update the temps in the grid structure with the newTemps array
for( i = 0; i < numGridBoxes; i++) {
grid[i].temp = newTemps[i];
}
}
/*
* Stop the timers
*/
time(&endTime);
clockTime = clock() - clockTime;
printf("*********************************************************************\n");
printf("Num Threads: %3d\n", numThreads);
printf("dissipation converged in %d iterations,\n", iter);
printf("\twith max DSV\t= %lf and min DSV\t= %lf\n", maxTemp, minTemp);
printf("\taffect rate\t= %lf;\tepsilon\t= %lf\n", affectRate, epsilon);
printf("\n");
printf("elapsed convergence loop time\t(clock): %lu\n", clockTime);
printf("elapsed convergence loop time\t (time): %.f\n", difftime(endTime, startTime));
printf("*********************************************************************\n");
/*
* Free the memory of all grid boxes, the temporary 'newTemps' variable, the threads, and the storage box
*/
for( i = 0; i < numGridBoxes; i++ ) {
free(grid[i].neiTemps);
free(grid[i].neiCD);
}
free(grid);
free(newTemps);
free(threads);
free(storage);
return 0;
}
//.........这里部分代码省略.........
if (!IS_VALID_SOCKET(sd)) {
JK_TRACE_EXIT(l);
return -1;
}
save_errno = errno;
if (JK_IS_DEBUG_LEVEL(l)) {
sb = jk_dump_sinfo(sd, buf, sizeof(buf));
jk_log(l, JK_LOG_DEBUG, "About to shutdown socket %d [%s]",
sd, sb);
}
/* Shut down the socket for write, which will send a FIN
* to the peer.
*/
if (shutdown(sd, SHUT_WR)) {
rc = jk_close_socket(sd, l);
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG,
"Failed sending SHUT_WR for socket %d [%s]",
sd, sb);
errno = save_errno;
JK_TRACE_EXIT(l);
return rc;
}
do {
rp = 0;
if (jk_is_input_event(sd, timeout, l)) {
/* Do a restartable read on the socket
* draining out all the data currently in the socket buffer.
*/
int num = 0;
do {
num++;
#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
rc = recv(sd, &dummy[0], sizeof(dummy), 0);
if (JK_IS_SOCKET_ERROR(rc))
JK_GET_SOCKET_ERRNO();
#else
rc = read(sd, &dummy[0], sizeof(dummy));
#endif
if (rc > 0)
rp += rc;
} while (JK_IS_SOCKET_ERROR(rc) && (errno == EINTR || errno == EAGAIN) && num < MAX_READ_RETRY);
if (rc < 0) {
/* Read failed.
* Bail out from the loop.
*/
break;
}
}
else {
/* Error or timeout (reason is logged within jk_is_input_event)
* Exit the drain loop
*/
break;
}
rd += rp;
if (rp < sizeof(dummy)) {
if (timeout > MS_TO_LINGER_LAST) {
/* Try one last time with a short timeout
*/
timeout = MS_TO_LINGER_LAST;
continue;
}
/* We have read less then size of buffer
* It's a good chance there will be no more data
* to read.
*/
if ((rc = sononblock(sd))) {
rc = jk_close_socket(sd, l);
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG,
"error setting socket %d [%s] to nonblocking",
sd, sb);
errno = save_errno;
JK_TRACE_EXIT(l);
return rc;
}
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG,
"shutting down the read side of socket %d [%s]",
sd, sb);
shutdown(sd, SHUT_RD);
break;
}
timeout = MS_TO_LINGER;
} while ((rd < MAX_LINGER_BYTES) && (difftime(time(NULL), start) < MAX_SECS_TO_LINGER));
rc = jk_close_socket(sd, l);
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG,
"Shutdown socket %d [%s] and read %d lingering bytes in %d sec.",
sd, sb, rd, (int)difftime(time(NULL), start));
errno = save_errno;
JK_TRACE_EXIT(l);
return rc;
}
请发表评论