static int lua_download(lua_State *L) { // Flush the lua output (it seems to buffered separately) do_flush(L, "stdout"); do_flush(L, "stderr"); // Extract params luaL_checktype(L, 1, LUA_TFUNCTION); int pcount = lua_gettop(L); const char *url = luaL_checkstring(L, 2); const char *cacert = NULL; if (pcount >= 3 && !lua_isnil(L, 3)) cacert = luaL_checkstring(L, 3); const char *crl = NULL; if (pcount >= 4 && !lua_isnil(L, 4)) crl = luaL_checkstring(L, 4); bool ocsp = lua_toboolean(L, 5); bool ssl = lua_toboolean(L, 6); // Handle the callback struct lua_download_data *data = malloc(sizeof *data); data->L = L; data->callback = register_value(L, 1); // Run the download struct events *events = extract_registry(L, "events"); ASSERT(events); struct wait_id id = download(events, download_callback, data, url, cacert, crl, ocsp, ssl); // Return the ID push_wid(L, &id); return 1; }
int filebuf::overflow(int c) { if (xflags() & _S_NO_WRITES) // SET ERROR return EOF; // Allocate a buffer if needed. if (base() == NULL) { doallocbuf(); if (xflags() & _S_LINE_BUF+_S_UNBUFFERED) setp(_base, _base); else setp(_base, _ebuf); setg(_base, _base, _base); _flags |= _S_CURRENTLY_PUTTING; } // If currently reading, switch to writing. else if ((_flags & _S_CURRENTLY_PUTTING) == 0) { if (xflags() & _S_LINE_BUF+_S_UNBUFFERED) setp(gptr(), gptr()); else setp(gptr(), ebuf()); setg(egptr(), egptr(), egptr()); _flags |= _S_CURRENTLY_PUTTING; } if (c == EOF) return do_flush(); if (pptr() == ebuf() ) // Buffer is really full if (do_flush() == EOF) return EOF; xput_char(c); if (unbuffered() || (linebuffered() && c == '\n')) if (do_flush() == EOF) return EOF; return (unsigned char)c; }
static int lua_run_generic(lua_State *L, bool utils) { // Flush the lua output (it seems to buffered separately) do_flush(L, "stdout"); do_flush(L, "stderr"); // Extract the parameters. There's a lot of them. luaL_checktype(L, 1, LUA_TFUNCTION); int pf_cback_type = lua_type(L, 2); if (pf_cback_type != LUA_TNIL && pf_cback_type != LUA_TFUNCTION) return luaL_error(L, "The 2nd argument of run_command must be either function or nil"); if (!lua_isnil(L, 3) && !lua_isstring(L, 3)) return luaL_error(L, "The 3rd argument of run_command is a string input or nil"); int term_timeout = luaL_checkinteger(L, 4); int kill_timeout = luaL_checkinteger(L, 5); const char *cmd = luaL_checkstring(L, 6); struct log_buffer log; log_buffer_init(&log, LL_DBG); // The rest of the args are args for the command ‒ get them into an array const size_t arg_count = (size_t)lua_gettop(L) - 6; const char *args[arg_count + 1]; for (int i = 6; i < lua_gettop(L); i ++) { args[i - 6] = luaL_checkstring(L, i + 1); if (log.f) fprintf(log.f, "%s ", args[i - 6]); } args[arg_count] = NULL; if (log.f) { fclose(log.f); if (utils) { DBG("Util command: %s %s", cmd, log.char_buffer); } else DBG("Command: %s %s", cmd, log.char_buffer); free(log.char_buffer); } // Data for the callbacks. It will get freed there. struct lua_command_data *data = malloc(sizeof *data); data->L = L; data->terminated_callback = register_value(L, 1); data->postfork_callback = lua_isnil(L, 2) ? NULL : register_value(L, 2); struct events *events = extract_registry(L, "events"); ASSERT(events); size_t input_size = 0; const char *input = NULL; if (lua_isstring(L, 3)) input = lua_tolstring(L, 3, &input_size); struct wait_id id; if (utils) id = run_util_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, cmd, args); else id = run_command_a(events, command_terminated, command_postfork, data, input_size, input, term_timeout, kill_timeout, cmd, args); push_wid(L, &id); // Return 1 value ‒ the wait_id return 1; }
/* * This is called when a user changes the value of the silent parameter. */ static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int len; struct vc_data *vc = vc_cons[fg_console].d; char ch = 0; char shut; unsigned long flags; len = strlen(buf); if (len > 0 && len < 3) { ch = buf[0]; if (ch == '\n') ch = '0'; } if (ch < '0' || ch > '7') { pr_warn("silent value '%c' not in range (0,7)\n", ch); return -EINVAL; } spk_lock(flags); if (ch&2) { shut = 1; do_flush(); } else { shut = 0; } if (ch&4) shut |= 0x40; if (ch&1) spk_shut_up |= shut; else spk_shut_up &= ~shut; spk_unlock(flags); return count; }
/* Suspend curses while running an external program */ static ELVBOOL vio_prgopen (char *command, /* the shell command to run */ ELVBOOL willwrite, /* redirect stdin from elvis */ ELVBOOL willread) /* redirect stdiout back to elvis */ { /* unless both stdin and stdout/stderr are going to be redirected, * move the cursor to the bottom of the screen before running program. */ isfilter = (ELVBOOL)(willwrite && willread); if (!isfilter) { vio_CM (o_ttyrows - 1, 0); vio_CE (vc_term); vio_reset (); do_flush (); /* suspend curses */ vio_suspend (); } /* try to call the regular prgopen(); if it fails, then clean up */ if (!prgopen (command, willwrite, willread)) { if (!isfilter) vio_resume (ElvTrue); return ElvFalse; } return ElvTrue; }
void STDCALL flush_thread(void* context) { DEVICE_OBJECT* devobj = context; device_extension* Vcb = devobj->DeviceExtension; LARGE_INTEGER due_time; ObReferenceObject(devobj); KeInitializeTimer(&Vcb->flush_thread_timer); due_time.QuadPart = -INTERVAL * 10000; KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL); while (TRUE) { KeWaitForSingleObject(&Vcb->flush_thread_timer, Executive, KernelMode, FALSE, NULL); if (!(devobj->Vpb->Flags & VPB_MOUNTED) || Vcb->removing) break; do_flush(Vcb); KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL); } ObDereferenceObject(devobj); KeCancelTimer(&Vcb->flush_thread_timer); KeSetEvent(&Vcb->flush_thread_finished, 0, FALSE); PsTerminateSystemThread(STATUS_SUCCESS); }
static void do_flush_all(void) { ip_pool_t i, highest = high_nr(); for (i=0; i<=highest; i++) do_flush(i); }
static OMX_ERRORTYPE oggdmux_prc_port_flush (const void * ap_obj, OMX_U32 TIZ_UNUSED (a_pid)) { oggdmux_prc_t * p_prc = (oggdmux_prc_t *) ap_obj; assert (p_prc); return do_flush (p_prc); }
void close(Promise<> promise) { do_flush(true /*force*/); kv_safe_.reset(); kv_ = nullptr; stop(); promise.set_value(Unit()); }
GstVaapiDecoderStatus gst_vaapi_decoder_flush (GstVaapiDecoder * decoder) { g_return_val_if_fail (decoder != NULL, GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); return do_flush (decoder); }
/* Send any required termination strings. Turn off "raw" mode. */ static void vio_suspend (void) { /* revert to the normal font */ vio_revert (NULL); do_flush (); raw_mode = ElvFalse; }
/* Flush any changes out to the display */ static void vio_flush (void) { if (current) { movecurs (current); } do_flush (); vio_CM (c_row, c_col); }
/* shut down the VIO interface */ static void vio_term (void) { cursorshape (CURSOR_NONE); /* change the terminal mode back the way it was */ vio_suspend (); do_flush (); }
int lib_gzflush (gzFile file, int flush) { gz_stream *s = (gz_stream*)file; int err = do_flush (file, flush); if (err) return err; F_FFLUSH(s->file); // FIO- return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; }
void cbuf_ack (cbuf_t* cb, cbsize_t len) { if (len) { // len must not be 0 or cb->empty could mistakingly flip if ((cb->read += len) >= cb->size) cb->read -= cb->size; if ((cb->empty = (cb->read == cb->write))) do_flush(cb); // bigger chunk, less loop } }
/* * FUNCTION UTL_FILE.FFLUSH(file UTL_FILE.FILE_TYPE) * RETURNS void; * * This function makes sure that all pending data for the specified file is written * physically out to file. * * Exceptions: * INVALID_FILEHANDLE, INVALID_OPERATION, WRITE_ERROR */ Datum utl_file_fflush(PG_FUNCTION_ARGS) { FILE *f; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), NULL, NULL); do_flush(f); PG_RETURN_VOID(); }
void PrintBase::flush() { if( char *beg=ptr ) { ulen len=Dist(beg,cur); clear(); do_flush(beg,len); } }
/* Set a window's cursor position. */ static void vio_moveto (GUIWIN *gw, /* window whose cursor is to be moved */ int column, /* new column of cursor */ int row) /* new row of cursor */ { VWIN *vw = (VWIN *)gw; do_flush (); vw->cursy = row; vw->cursx = column; }
static OMX_ERRORTYPE oggdmux_prc_stop_and_return (void * ap_obj) { oggdmux_prc_t * p_prc = ap_obj; assert (p_prc); /* Reset the internal EOS flags */ p_prc->aud_eos_ = false; p_prc->vid_eos_ = false; p_prc->file_eos_ = false; TIZ_TRACE (handleOf (p_prc), "stop_and_return"); return do_flush (p_prc); }
void set(string key, string value, Promise<> promise) { auto it = buffer_.find(key); if (it != buffer_.end()) { it->second = std::move(value); } else { buffer_.emplace(std::move(key), std::move(value)); } if (promise) { buffer_promises_.push_back(std::move(promise)); } cnt_++; do_flush(false /*force*/); }
/* This function is used internally. It is passed to the tputs() function * which uses it to output individual characters. This function saves the * characters in a buffer and outputs them in a bunch. */ static int ttych(int ch) { if (raw_mode) { switch (ch) { case '\n': do_flush (); c_col = 0; c_row++; break; case '\r': do_flush (); c_col = 0; break; default: ttybuf[ttycount++] = ch; ttybuf[ttycount++] = vc_current; if (ttycount >= QTY (ttybuf)) { do_flush (); } break; } } else { ttybuf[ttycount++] = ch; if (ttycount >= QTY (ttybuf)) { do_flush (); } } return ch; }
void erase(string key, Promise<> promise) { auto it = buffer_.find(key); if (it != buffer_.end()) { it->second = optional<string>(); } else { buffer_.emplace(std::move(key), optional<string>()); } if (promise) { buffer_promises_.push_back(std::move(promise)); } cnt_++; do_flush(false /*force*/); }
int filebuf::sync() { // char* ptr = cur_ptr(); if (pptr() > pbase()) if (do_flush()) return EOF; if (gptr() != egptr()) { streampos delta = gptr() - egptr(); if (in_backup()) delta -= eGptr() - Gbase(); if (sys_seek(delta, ios::cur) == EOF) return EOF; } // FIXME: Cleanup - can this be shared? // setg(base(), ptr, ptr); return 0; }
Datum utl_file_put_line(PG_FUNCTION_ARGS) { FILE *f; bool autoflush; f = do_put(fcinfo); autoflush = PG_GETARG_IF_EXISTS(2, BOOL, false); do_new_line(f, 1); if (autoflush) do_flush(f); PG_RETURN_BOOL(true); }
void STDCALL flush_thread(void* context) { device_extension* Vcb = context; LARGE_INTEGER due_time; KeInitializeTimer(&Vcb->flush_thread_timer); due_time.QuadPart = -INTERVAL * 10000; KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL); while (TRUE) { KeWaitForSingleObject(&Vcb->flush_thread_timer, Executive, KernelMode, FALSE, NULL); do_flush(Vcb); KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL); } KeCancelTimer(&Vcb->flush_thread_timer); PsTerminateSystemThread(STATUS_SUCCESS); }
int filebuf::underflow() { #if 0 /* SysV does not make this test; take it out for compatibility */ if (fp->_flags & __SEOF) return (EOF); #endif if (xflags() & _S_NO_READS) return EOF; if (gptr() < egptr()) return *(unsigned char*)gptr(); allocbuf(); // FIXME This can/should be moved to __streambuf ?? if ((xflags() & _S_LINE_BUF) || unbuffered()) { // Flush all line buffered files before reading. streambuf::flush_all_linebuffered(); } #if 1 if (pptr() > pbase()) if (do_flush()) return EOF; #endif _G_ssize_t count = sys_read(base(), ebuf() - base()); if (count <= 0) { if (count == 0) xsetflags(_S_EOF_SEEN); else xsetflags(_S_ERR_SEEN), count = 0; } setg(base(), base(), base() + count); setp(base(), base()); if (count == 0) return EOF; if (_fb._offset >= 0) _fb._offset += count; return *(unsigned char*)gptr(); }
cbsize_t cbuf_read (cbuf_t* cb, char* data, cbsize_t desired_len) { // cb->read must always be equal when using this function // (do not use cbuf_*_ptr) cbsize_t want = desired_len; cbsize_t ret = 0; while (want && !cbuf_is_empty(cb)) { cbsize_t readable_len = cb->read >= cb->write? cb->size - cb->read: cb->write - cb->read; cbsize_t chunk = (want > readable_len)? readable_len: want; memcpy(data + ret, cb->buf + cb->read, chunk); ret += chunk; want -= chunk; if ((cb->read += chunk) == cb->size) cb->read = 0; if ((cb->empty = cb->allread = (cb->read == cb->write))) do_flush(cb); // bigger_chunk, less loop } return ret; }
/* =========================================================================== Flushes all pending output if necessary, closes the compressed file and deallocates all the (de)compression state. */ int lib_gzclose (gzFile file) { #ifndef NO_DEFLATE int err; #endif gz_stream *s = (gz_stream*)file; if (s == NULL) return Z_STREAM_ERROR; if (s->mode == 'w') { #ifdef NO_DEFLATE return Z_STREAM_ERROR; #else err = do_flush (file, Z_FINISH); if (err != Z_OK) return destroy((gz_stream*)file); putLong (s->file, s->crc); putLong (s->file, s->stream.total_in); #endif } return destroy((gz_stream*)file); }
enum ssl_hs_wait_t tls13_server_handshake(SSL *ssl) { SSL_HANDSHAKE *hs = ssl->s3->hs; while (hs->state != state_done) { enum ssl_hs_wait_t ret = ssl_hs_error; enum server_hs_state_t state = hs->state; switch (state) { case state_process_client_hello: ret = do_process_client_hello(ssl, hs); break; case state_select_parameters: ret = do_select_parameters(ssl, hs); break; case state_send_hello_retry_request: ret = do_send_hello_retry_request(ssl, hs); break; case state_flush_hello_retry_request: ret = do_flush_hello_retry_request(ssl, hs); break; case state_process_second_client_hello: ret = do_process_second_client_hello(ssl, hs); break; case state_send_server_hello: ret = do_send_server_hello(ssl, hs); break; case state_send_encrypted_extensions: ret = do_send_encrypted_extensions(ssl, hs); break; case state_send_certificate_request: ret = do_send_certificate_request(ssl, hs); break; case state_send_server_certificate: ret = do_send_server_certificate(ssl, hs); break; case state_send_server_certificate_verify: ret = do_send_server_certificate_verify(ssl, hs, 1 /* first run */); break; case state_complete_server_certificate_verify: ret = do_send_server_certificate_verify(ssl, hs, 0 /* complete */); break; case state_send_server_finished: ret = do_send_server_finished(ssl, hs); break; case state_flush: ret = do_flush(ssl, hs); break; case state_process_client_certificate: ret = do_process_client_certificate(ssl, hs); break; case state_process_client_certificate_verify: ret = do_process_client_certificate_verify(ssl, hs); break; case state_process_client_finished: ret = do_process_client_finished(ssl, hs); break; case state_send_new_session_ticket: ret = do_send_new_session_ticket(ssl, hs); break; case state_flush_new_session_ticket: ret = do_flush_new_session_ticket(ssl, hs); break; case state_done: ret = ssl_hs_ok; break; } if (ret != ssl_hs_ok) { return ret; } } return ssl_hs_ok; }
int main( int argc, char **argv ) { int retval; int num_events; long long *values; char *success; PAPI_event_info_t info; int EventSet = PAPI_NULL; int i, j, data_type, event; int u_format = 0; int hex_format = 0; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* Automatically pass if no events, for run_tests.sh */ if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) { test_pass( __FILE__, NULL, 0 ); } values = ( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc ); success = ( char * ) malloc( ( size_t ) argc ); if ( success == NULL || values == NULL ) test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS ); for ( num_events = 0, i = 1; i < argc; i++ ) { if ( !strcmp( argv[i], "-h" ) ) { print_help( argv ); exit( 1 ); } else if ( !strcmp( argv[i], "-u" ) ) { u_format = 1; } else if ( !strcmp( argv[i], "-x" ) ) { hex_format = 1; } else { if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) { printf( "Failed adding: %s\nbecause: %s\n", argv[i], PAPI_strerror(retval)); } else { success[num_events++] = i; printf( "Successfully added: %s\n", argv[i] ); } } } /* Automatically pass if no events, for run_tests.sh */ if ( num_events == 0 ) { test_pass( __FILE__, NULL, 0 ); } printf( "\n" ); do_flops( 1 ); do_flush( ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) { test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( NUM_FLOPS ); do_misses( 1, L1_MISS_BUFFER_SIZE_INTS ); if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); for ( j = 0; j < num_events; j++ ) { i = success[j]; if (! (u_format || hex_format) ) { retval = PAPI_event_name_to_code( argv[i], &event ); if (retval == PAPI_OK) { retval = PAPI_get_event_info(event, &info); if (retval == PAPI_OK) data_type = info.data_type; else data_type = PAPI_DATATYPE_INT64; } switch (data_type) { case PAPI_DATATYPE_UINT64: printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] ); break; case PAPI_DATATYPE_FP64: printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) ); j++; break; case PAPI_DATATYPE_BIT64: printf( "%s : \t0x%llX", argv[i], values[j] ); break; case PAPI_DATATYPE_INT64: default: printf( "%s : \t%lld", argv[i], values[j] ); break; } if (retval == PAPI_OK) printf( " %s", info.units ); printf( "\n" ); } if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] ); if (hex_format) printf( "%s : \t0x%llX\n", argv[i], values[j] ); } printf( "\n----------------------------------\n" ); printf ( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }