void web_child(int sockfd) { int ntowrite, n; ssize_t nread; // result array contain random charactors char line[MAXLINE], result[MAXBTYE]; for (;;) { if ((nread = recv(sockfd, line, MAXLINE, 0)) == 0) { echo("[SERVER] connection closed by client.\n"); return; } echo("[SERVER] received from client [%s].\n", line); ntowrite = atol(line); if ((ntowrite <= 0) || (ntowrite > MAXBTYE)) { echo("[SERVER] client request for %d bytes.\n", ntowrite); return; } //echo("[SERVER] send to client [%s].\n", result); if ((n = written(sockfd, result, ntowrite)) != ntowrite) echo("[SERVER] Error: expect write %d bytes, actually write %d bytes.\n", ntowrite, n); //echo("[SERVER] Debug: wrote %d bytes to client.\n", n); } }
void GPcapFileWriter::write(GPacket* packet) { struct pcap_pkthdr pkthdr; pkthdr.ts = packet->ts_; pkthdr.caplen = pkthdr.len = (bpf_u_int32)packet->buf_.size_; pcap_dump((u_char*)pcap_dumper_, &pkthdr, packet->buf_.data_); emit written(packet); }
//*************************************************************************** void Kwave::MultiWriter::proceeded() { bool overwrite = tracks() && at(0) && (at(0)->mode() == Kwave::Overwrite); if (overwrite) { qreal sum = 0; qreal total = 0; unsigned int track; const unsigned int tracks = this->tracks(); for (track = 0; track < tracks; ++track) { const Kwave::Writer *w = at(track); if (w) { sum += w->position() - w->first(); total += w->last() - w->first(); } } emit progress(qreal(100.0) * sum / total); } else { quint64 sum = 0; unsigned int track; const unsigned int tracks = this->tracks(); for (track = 0; track < tracks; ++track) { const Kwave::Writer *w = at(track); if (w) sum += w->position() - w->first(); } emit written(sum); } }
/** Constructeur par defaut - cree un schema contenant une collection d'elements vide et un schema vide. @param diagrams Nombre de nouveaux schemas a ajouter a ce nouveau projet @param parent QObject parent */ QETProject::QETProject(int diagrams, QObject *parent) : QObject (parent), collection_ (0 ), project_qet_version_ (-1 ), modified_ (false ), read_only_ (false ), titleblocks_ (this ), folioSheetsQuantity (0 ), m_auto_conductor (true ) { // 0 a n schema(s) vide(s) int diagrams_count = qMax(0, diagrams); for (int i = 0 ; i < diagrams_count ; ++ i) { addNewDiagram(); } // une collection d'elements vide collection_ = new XmlElementsCollection(); collection_ -> setProtocol("embed"); collection_ -> setProject(this); connect(collection_, SIGNAL(written()), this, SLOT(componentWritten())); // une categorie dediee aux elements integres automatiquement ensureIntegrationCategoryExists(); setupTitleBlockTemplatesCollection(); undo_stack_ = new QUndoStack(); connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool))); }
bool clIndexerProtocol::SendReply(clNamedPipe* conn, clIndexerReply& reply) { size_t buff_size(0); char *data = reply.toBinary(buff_size); CharDeleter deleter(data); // send the reply size size_t written(0); conn->write((void*)&buff_size, sizeof(buff_size), &written, -1); int bytes_left(buff_size); int bytes_to_write(0); int bytes_written(0); while (bytes_left > 0) { // we write in chunks of 3000 bytes if (bytes_left < 3000) { bytes_to_write = bytes_left; } else { bytes_to_write = 3000; } size_t actual_written(0); if ( !conn->write(data+bytes_written, bytes_to_write, &actual_written, -1) ) { return false; } bytes_left -= actual_written; bytes_written += actual_written; } // the above problem does not exist under Windows' NamedPipes return true; }
/** Computes yy = M xx. yy is allocated, not necessarily set. */ void coo_matvec(PyObject *yy_py, PyObject *xx_py, bool ignore_nan, size_t M_nrow, size_t M_ncol, PyObject *M_row_py, PyObject *M_col_py, PyObject *M_data_py) { auto xx(np_to_blitz<double,1>(xx_py, "xx", {M_ncol})); auto yy(np_to_blitz<double,1>(yy_py, "yy", {M_nrow})); auto M_row(np_to_blitz<int,1>(M_row_py, "M_row_py", {-1})); auto M_col(np_to_blitz<int,1>(M_col_py, "M_col_py", {-1})); auto M_data(np_to_blitz<double,1>(M_data_py, "M_data_py", {-1})); // Keep track of which items we've written to. std::vector<bool> written(M_nrow, false); // Do the multiplication, and we're done! int nnz = M_data.size(); for (int n=0; n<nnz; ++n) { size_t row = M_row(n); size_t col = M_col(n); double data = M_data(n); // Ignore NaN in input vector if (ignore_nan && std::isnan(xx(col))) continue; // Just do Snowdrift-style "REPLACE". "MERGE" was never used. double old_yy; if (written[row]) { old_yy = yy(row); } else { old_yy = 0; written[row] = true; } yy(row) = old_yy + data * xx(col); } }
void MemoryStreamBuf::position(UInt32 pos) { written(); // Save nb char written setp(_pBuffer,_pBuffer + _bufferSize); if(pos>_bufferSize) pos = _bufferSize; pbump((int)pos); setg(_pBuffer,_pBuffer+pos,_pBuffer + _bufferSize); }
bool writeFrame(const QCanBusFrame &/*data*/) { if (state() != QCanBusDevice::ConnectedState) return false; emit written(); return true; }
GPacket::Result GPcapDeviceWriter::write(GPacket* packet) { int i = pcap_sendpacket(pcap_, packet->buf_.data_, (int)packet->buf_.size_); if (i == 0) { emit written(packet); return GPacket::Ok; } qWarning() << QString("pcap_sendpacket return %1").arg(i); return GPacket::Fail; }
bool XmlElementDefinition::write() { /* Contrairement a un schema, cet objet ne contient pas deux versions de l'element (element avant edition et element edite) Cette methode ne fait donc rien d'autre qu'emettre le signal written(), le travail ayant deja ete fait par la methode setXml(). */ emit(written()); return(true); }
PyObject *StdOutWrite(PyObject *self, PyObject *args) { std::size_t written(0); StdOut *selfimpl = reinterpret_cast<StdOut *>(self); if (selfimpl->write) { char *data; if (!PyArg_ParseTuple(args, "s", &data)) return 0; std::string str(data); selfimpl->write(str); written = str.size(); } return PyLong_FromSize_t(written); }
void FGFSIoTelnet::slotIoWrite(const QByteArray& obuffer){ //DEBUGH("to send:", obuffer); if (!m_internal_connected) { //DEBUGP(LOGWARNING, "not connected(?)"); return; } if (m_telnetchannel.push((obuffer.trimmed() + m_telnetchannel.getTerminator()).data())) { //DEBUGP(LOGDEBUG, "pushed"); slotIoRead(); emit written(); } return; };
PyObject* PyStream_write(PyObject* self, PyObject* args) { std::size_t written(0); PyStream* selfimpl = reinterpret_cast<PyStream*>(self); if (selfimpl->stream) { char* data; if (!PyArg_ParseTuple(args, "s", &data)) return 0; std::string str(data); // TODO: Make log prefix parameterizables *(selfimpl->stream) << std::string("PyR: ") << str << std::endl; written = str.size(); } return PyLong_FromSize_t(written); }
//! this is the gold standard for images. If we get this working, we have a leg up in making progress on the other formats. static bool testBitmap() { // load a bitmap, store it, then load it again. Compare what we loaded the final time with a procedurally generated version try { std::stringstream ss; ss << basePath << "/procedural-reference.bmp"; util::Image loaded(ss.str()); if (!loaded.good() || loaded.width() != 256 || loaded.height() != 64) { report( "Did not load " << ss.str() << " correctly." ); return false; } util::Image *procedural = generateTestImage(); if (!compareImageByteLevel(*procedural, loaded)) { report( "Failed comparison check between 'procedural-reference.bmp' loaded by VerifyImage and a procedurally generated version." ); delete procedural; return false; } loaded.write("test-bitmap-output.bmp"); util::Image written("test-bitmap-output.bmp"); if (!compareImageByteLevel(loaded, written)) { report( "Failed to comparison check between " << ss.str() << " and test-bitmap-output.bmp" ); return false; } if (!compareImageByteLevel(*procedural, written)) { report( "Failed comparison check between 'test-bitmap-output.bmp' loaded by VerifyImage and a procedurally generated version." ); delete procedural; return false; } delete procedural; } catch (std::runtime_error &e) { report( "testBitmap exception: " << e.what() ); return false; } // We've loaded a bitmap of known dimensions, written it, loaded it again, and compared image // values. We've then compared this to a procedurally generated version of same. It's safe to say // this works. If all images were bitmaps, we'd be done. Too bad. return true; }
size_t I1::write( std::FILE* out ) { for( ConstSynIter itr = synRoots.begin(); itr != synRoots.end(); ++itr ) { //convert roots into offsets try { Synonym* syn( document->synonym( *itr ) ); primary->addSynonym( syn->location() ); } catch( Class1Error& e ) { printError( e.code ); } } size_t written( primary->write( out ) ); std::sort( secondary.begin(), secondary.end(), ptrLess< IndexItem* >() ); for( IndexIter itr = secondary.begin(); itr != secondary.end(); ++itr ) written += ( *itr )->write( out ); return written; }
std::streamsize fill_buffer(std::string& b, std::streamsize void_size, std::streamsize total_size, bool fill, bool write_id, bool write_body) { std::streamsize written(0); if (write_id) { // Cheating on the IDs a bit - there is no protection here against // invalid IDs std::vector<char> tmp(tawara::ebml_int::encode_u(tawara::ids::Void)); b.append(&tmp[0], 0, tmp.size()); written += tmp.size(); } else { // Ensure the written body size is correct for the void's total size void_size -= 1; } if (write_body) { std::vector<char> tmp(tawara::vint::encode(void_size - written - 1)); b.append(&tmp[0], 0, tmp.size()); written += tmp.size(); int remaining(total_size - written); if (fill) { for (std::streamsize ii(0); ii < void_size; ++ii) { b.push_back(0); } written += void_size; remaining -= void_size; } if (remaining > 0) { for (int ii(0); ii < remaining; ++ii) { b.push_back(0xC0); } written += remaining; } } return written; }
bool clIndexerProtocol::SendRequest(clNamedPipe* conn, clIndexerRequest& req) { size_t size(0); size_t written(0); char *data = req.toBinary(size); CharDeleter deleter(data); // write request if (!conn->write((void*)&size, sizeof(size), &written, -1)) { printf("ERROR: [%s] protocol error: rc %d\n", __PRETTY_FUNCTION__, conn->getLastError()); return false; } int bytes_left(size); int bytes_to_write(0); int bytes_written(0); while (bytes_left > 0) { // we write in chunks of 3000 bytes if (bytes_left < 3000) { bytes_to_write = bytes_left; } else { bytes_to_write = 3000; } size_t actual_written(0); if ( !conn->write(data+bytes_written, bytes_to_write, &actual_written, -1) ) { return false; } bytes_left -= actual_written; bytes_written += actual_written; } return true; }
qint64 SignalDrivenStream::writeData(const char* data, qint64 maxSize) { qint64 size = maxSize; emit written(QByteArray(data, size)); return size; }
PyObject *coo_matvec_py(PyObject *self, PyObject *args, PyObject *kwds) { try { PyObject *mat_py = NULL; PyObject *xx_py = NULL; PyObject *yy_py = NULL; int ignore_nan = 0; static char const *keyword_list[] = {"mat", "xx", "yy", "ignore_nan", NULL}; if (!PyArg_ParseTupleAndKeywords( args, kwds, "OOO|i", const_cast<char **>(keyword_list), &mat_py, &xx_py, &yy_py, &ignore_nan)) { PyErr_SetString(PyExc_ValueError, "coo_matvec_py() called with invalid arguments."); return NULL; } printf("ignore_nan = %d\n", ignore_nan); int nancount = 0; // Cast and typecheck arguments giss::BlitzSparseMatrix mat(giss::py_to_BlitzSparseMatrix(mat_py, "mat")); auto xx(giss::py_to_blitz<double,1>(xx_py, "xx", {mat.ncol})); auto yy(giss::py_to_blitz<double,1>(yy_py, "yy", {mat.nrow})); // Keep track of which items we've written to. std::vector<bool> written(mat.nrow, false); // Do the multiplication, and we're done! int nnz = mat.size(); for (int n=0; n<nnz; ++n) { int row = mat.rows()(n); int col = mat.cols()(n); double val = mat.vals()(n); // Ignore NaN in input vector if ((ignore_nan != 0) && std::isnan(xx(col))) { continue; } // Just do Snowdrift-style "REPLACE". "MERGE" was never used. double old_yy; if (written[row]) { old_yy = yy(row); } else { old_yy = 0; written[row] = true; } yy(row) = old_yy + val * xx(col); } printf("nancount = %d\n", nancount); } catch(...) { return NULL; // Error } return Py_BuildValue("i", 0); }
void TempFile::flush() { if(written() > 0) { out_.write(reinterpret_cast<const char*>(get()), written()); clear(); } }