struct destination_url *new_destination_url(char *url) { struct destination_url *sq_dest; char *address; int port; char *path; if (simplehttp_parse_url(url, strlen(url), &address, &port, &path) == 0) { fprintf(stderr, "ERROR: invalid destination URL: %s\n", url); return NULL; } sq_dest = malloc(sizeof(struct destination_url)); _DEBUG("destination_url: %s\n", url); _DEBUG("\taddress: %s\n", address); _DEBUG("\tport: %d\n", port); _DEBUG("\tpath: %s\n", path); sq_dest->address = address; sq_dest->port = port; sq_dest->path = path; sq_dest->next = NULL; sq_dest->method = EVHTTP_REQ_GET; return sq_dest; }
struct ProfilerStat *profiler_new_stat(const char *name) { struct ProfilerStat *pstat; struct ProfilerEntry *entry; static struct ProfilerStat *last = NULL; int i; pstat = malloc(sizeof(struct ProfilerStat)); pstat->name = strdup(name); pstat->data = malloc(STAT_WINDOW_COUNT * sizeof(struct ProfilerData *)); for (i = 0; i < STAT_WINDOW_COUNT; i++) { pstat->data[i] = malloc(sizeof(struct ProfilerData)); pstat->data[i]->value = -1; } pstat->count = 0; pstat->index = 0; pstat->next = NULL; _DEBUG("%s: new ProfilerStat %p\n", __FUNCTION__, pstat); // build the linked list as we add stats if (last) { last->next = pstat; } last = pstat; entry = malloc(sizeof(struct ProfilerEntry)); entry->stat = pstat; _DEBUG("%s: new ProfilerEntry %p\n", __FUNCTION__, entry); HASH_ADD_KEYPTR(hh, profiler_entries, pstat->name, strlen(pstat->name), entry); return pstat; }
/** * returns -1 if id was smaller then the one here * returns 0 is the id was the same * returns 1 if it was added/updated */ int add_bid(struct bid_node** head, uint32_t broadcast_id, char src_ip[INET_ADDRSTRLEN]) { struct bid_node* ptr; for(ptr = *head; ptr != NULL; ptr = ptr->next) { if(0 == strcmp(ptr->src_ip, src_ip)) { _DEBUG("%s\n", "found maching bid node"); if(ptr->broadcast_id > broadcast_id) { _DEBUG("%s\n", "trying to add broadcast_id that was smaller"); return -1; } else if(ptr->broadcast_id == broadcast_id) { _DEBUG("%s\n", "trying to add broadcast_id that was equal"); return 0; } ptr->broadcast_id = broadcast_id; return 1; } } _DEBUG("%s\n", "did not find a matching bid_node, adding another"); ptr = malloc(sizeof(struct bid_node)); if(ptr == NULL) { _ERROR("%s\n", "malloc for bid_node failed"); exit(EXIT_FAILURE); } strncpy(ptr->src_ip, src_ip, INET_ADDRSTRLEN); ptr->broadcast_id = broadcast_id; ptr->next = *head; *head = ptr; return 1; }
CacheSession::CacheSession(ClientSession *session, const char *url, uint32_t file_ttl, uint32_t dir_ttl) : FilterSession(session) { m_dir_ttl = file_ttl; m_dir_ttl = dir_ttl; string tmp(url); make_hash64("md5", tmp, m_url_hash, true); tmp = url + string(":meta:") + get_client_id(); make_hash64("md5", tmp, m_meta_key, true); tmp = url + string(":data:") + get_client_id(); make_hash64("md5", tmp, m_data_key, true); m_base_dir = cacheBaseDir() + SEPSTR + m_url_hash; if (!dir_exists(m_base_dir.c_str()) && makedirs(m_base_dir.c_str()) < 0) { m_enable = false; _DEBUG("Disabling Cache Session: can't create"); } #if 0 else if (!can_write_dir(m_base_dir.c_str())) { m_enable = false; _DEBUG("Disabling Cache Session: can't write"); } #endif else { m_enable = true; _DEBUG("Enabling Cache Session"); } }
/** * init paramtes and states for attitudeUpdate * * @param * void * * @return * void * */ bool altitudeUpdateInit() { int calCount; attitudeIsInit=false; if(!parseMagnetCalibrationData(&calCount, mag_hard_iron_cal, mag_soft_iron_cal)){ _DEBUG(DEBUG_NORMAL,"Read magnet calibration data fail\n"); return false; } if(0 == calCount){ _DEBUG(DEBUG_NORMAL,"Use default magnet calibration data\n"); } _DEBUG(DEBUG_NORMAL,"Hard Iron: \n[%.3f %.3f %.3f]\n",mag_hard_iron_cal[0],mag_hard_iron_cal[1],mag_hard_iron_cal[2]); _DEBUG(DEBUG_NORMAL,"Soft Iron: \n[%.3f %.3f %.3f]\n[%.3f %.3f %.3f]\n[%.3f %.3f %.3f]\n", mag_soft_iron_cal[0][0],mag_soft_iron_cal[0][1],mag_soft_iron_cal[0][2], mag_soft_iron_cal[1][0],mag_soft_iron_cal[1][1],mag_soft_iron_cal[1][2], mag_soft_iron_cal[2][0],mag_soft_iron_cal[2][1],mag_soft_iron_cal[2][2]); #ifdef MPU6050_9AXIS initSmaFilterEntity(&x_magnetSmaFilterEntry,"X_MAGNET",2); initSmaFilterEntity(&y_magnetSmaFilterEntry,"Y_MAGNET",2); initSmaFilterEntity(&z_magnetSmaFilterEntry,"Z_MAGNET",2); #endif attitudeIsInit=true; return true; }
std::vector<double> D_Topo::node_qth(size_t tid) const{ std::vector<double> qth; if (contains(tid)) { // short cut circuit size_t short_cut = 0.5*cut_rate*get_topo_size(); if (tid<=short_cut || tid>=get_topo_size()-short_cut) { qth.push_back(0); double height = tid <= short_cut ? (double)tid/short_cut : (double)(get_topo_size()-tid)/short_cut; if (tid <= short_cut) { qth.push_back(height); } else { qth.push_back(-height); } return qth; } // normal circuit double vid = double(tid-short_cut); double angle = 0.5*PI - PI*(vid/(get_topo_size()-2*short_cut)); _DEBUG(angle); _DEBUG(angle/PI*180); qth.push_back(cos(angle)); qth.push_back(sin(angle)); } return qth; }
static FillBufferResult fill_buffer (struct neon_handle * h) { int bsize = free_rb (& h->rb); int to_read = MIN (bsize, NEON_NETBLKSIZE); char buffer[NEON_NETBLKSIZE]; bsize = ne_read_response_block (h->request, buffer, to_read); if (! bsize) { _DEBUG ("<%p> End of file encountered", h); return FILL_BUFFER_EOF; } if (bsize < 0) { _ERROR ("<%p> Error while reading from the network", (void *) h); ne_request_destroy (h->request); h->request = NULL; return FILL_BUFFER_ERROR; } _DEBUG ("<%p> Read %d bytes of %d", h, bsize, to_read); write_rb (& h->rb, buffer, bsize); return FILL_BUFFER_SUCCESS; }
void OnReceive ( boost::shared_ptr < ClassD::ByteArray > message ) { static unsigned long counter=1; struct timeval start, end, tmp_diff; float latency; _DEBUG("\n"); gettimeofday(&start, NULL); unsigned char *textMessage = message->GetData().get(); size_t len = message->GetSize(); int16_t RetValue = RESULT_SUCCESS; RetValue = onReceiveCallBack ((int8_t*)textMessage,len,1,CLASSD_INTERFACE); if (RetValue != RESULT_SUCCESS) { _DEBUG("ERROR in onReceiveCallBack"); } gettimeofday(&end, NULL); tmp_diff.tv_sec = end.tv_sec - start.tv_sec ; tmp_diff.tv_usec = end.tv_usec - start.tv_usec; while (tmp_diff.tv_usec<0) { tmp_diff.tv_usec+=1000000; tmp_diff.tv_sec -=1; } latency = tmp_diff.tv_sec + ((float)tmp_diff.tv_usec/1000000); _DEBUG("Counter: [%u] Time elapsed: [%2.6f seconds]\n", counter, latency); }
int buffered_socket_connect(struct BufferedSocket *buffsock) { struct addrinfo ai, *aitop; char strport[32]; struct sockaddr *sa; int slen; long flags; if ((buffsock->state == BS_CONNECTED) || (buffsock->state == BS_CONNECTING)) { return 0; } memset(&ai, 0, sizeof(struct addrinfo)); ai.ai_family = AF_INET; ai.ai_socktype = SOCK_STREAM; snprintf(strport, sizeof(strport), "%d", buffsock->port); if (getaddrinfo(buffsock->address, strport, &ai, &aitop) != 0) { _DEBUG("%s: getaddrinfo() failed\n", __FUNCTION__); return 0; } sa = aitop->ai_addr; slen = aitop->ai_addrlen; if ((buffsock->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { _DEBUG("%s: socket() failed\n", __FUNCTION__); return 0; } // set non-blocking if ((flags = fcntl(buffsock->fd, F_GETFL, NULL)) < 0) { close(buffsock->fd); _DEBUG("%s: fcntl(%d, F_GETFL) failed\n", __FUNCTION__, buffsock->fd); return 0; } if (fcntl(buffsock->fd, F_SETFL, flags | O_NONBLOCK) == -1) { close(buffsock->fd); _DEBUG("%s: fcntl(%d, F_SETFL) failed\n", __FUNCTION__, buffsock->fd); return 0; } if (connect(buffsock->fd, sa, slen) == -1) { if (errno != EINPROGRESS) { close(buffsock->fd); _DEBUG("%s: connect() failed\n", __FUNCTION__); return 0; } } freeaddrinfo(aitop); ev_once(buffsock->loop, buffsock->fd, EV_WRITE, 2.0, buffered_socket_connect_cb, buffsock); buffsock->state = BS_CONNECTING; return buffsock->fd; }
static void kill_reader (struct neon_handle * h) { _DEBUG ("Signaling reader thread to terminate"); pthread_mutex_lock (& h->reader_status.mutex); h->reader_status.reading = FALSE; pthread_cond_broadcast (& h->reader_status.cond); pthread_mutex_unlock (& h->reader_status.mutex); _DEBUG ("Waiting for reader thread to die..."); pthread_join (h->reader, NULL); _DEBUG ("Reader thread has died"); }
bool ServerPasswd::validate(const char *type, const char *c_uname, const char *s_mnt_name, const char *s_nonce, const char *c_pwd, string& base) { ASSERT(c_uname); ASSERT(s_mnt_name); ASSERT(s_nonce); ASSERT(c_pwd); _DEBUG("VALIDATE: uname=%s mnt_name=%s nonce=%s pwd=%s", c_uname, s_mnt_name, s_nonce, c_pwd); struct server_passwd_entry e; string hash = userToKey(c_uname, s_mnt_name); ScopedMutex lock(&pwd_mutex); ServerPasswd p(Config::instance()->pwd_file().c_str()); bool found = p.getEntry(hash, e); _DEBUG("VALIDATE hash=%s found=%s", hash.c_str(), BOOL_STR(found)); if (found) { time_t now = time(0); if (e.expires > 0 && (uint64_t) now > e.expires) { return false; } #if 1 // CryptoUtils password check if (!passwd_check(type, e.passwd, s_nonce, c_pwd)) { return false; } #else // nonce + pwd == c_pwd string pwd = s_nonce; pwd += b64std2inet(e.passwd); #ifndef OLD_KEY make_hash64(type, pwd, pwd); #else sha2_digest_t digest; make_sha2(pwd, &digest); sha2_base64(&digest, pwd); #endif _DEBUG("VALIDATE: new_pwd=%s entry_pwd=%s", pwd.c_str(), e.passwd.c_str()); if (b64inet2std(c_pwd) != b64inet2std(pwd)) { return false; } #endif base = e.base; } return found; }
/** * update attitude * * @param * void * * @return * void * */ void attitudeUpdate(){ float yrpAttitude[3]; float pryRate[3]; float xyzAcc[3]; float xComponent[3]; float yComponent[3]; float zComponent[3]; float xyzMagnet[3]; #if CHECK_ATTITUDE_UPDATE_LOOP_TIME struct timeval tv_c; static struct timeval tv_l; unsigned long timeDiff=0; gettimeofday(&tv_c,NULL); timeDiff=GET_USEC_TIMEDIFF(tv_c,tv_l); _DEBUG(DEBUG_NORMAL,"attitude update duration=%ld us\n",timeDiff); UPDATE_LAST_TIME(tv_c,tv_l); #endif getYawPitchRollInfo(yrpAttitude, pryRate, xyzAcc, xComponent, yComponent, zComponent,xyzMagnet); setYaw(yrpAttitude[0]); setRoll(yrpAttitude[1]); setPitch(yrpAttitude[2]); setYawGyro(-pryRate[2]); setPitchGyro(pryRate[0]); setRollGyro(-pryRate[1]); setXAcc(xyzAcc[0]); setYAcc(xyzAcc[1]); setZAcc(xyzAcc[2]); setXGravity(zComponent[0]); setYGravity(zComponent[1]); setZGravity(zComponent[2]); setVerticalAcceleration(deadband((getXAcc() * zComponent[0] + getYAcc() * zComponent[1] + getZAcc() * zComponent[2] - 1.f) * 100.f,3.f) ); setXAcceleration(deadband((getXAcc() * xComponent[0] + getYAcc() * xComponent[1] + getZAcc() * xComponent[2]) * 100.f,3.f) ); setYAcceleration(deadband((getXAcc() * yComponent[0] + getYAcc() * yComponent[1] + getZAcc() * yComponent[2]) * 100.f,3.f) ); _DEBUG(DEBUG_ATTITUDE, "(%s-%d) ATT: Roll=%3.3f Pitch=%3.3f Yaw=%3.3f\n", __func__, __LINE__, getRoll(), getPitch(), getYaw()); _DEBUG(DEBUG_GYRO, "(%s-%d) GYRO: Roll=%3.3f Pitch=%3.3f Yaw=%3.3f\n", __func__, __LINE__, getRollGyro(), getPitchGyro(), getYawGyro()); _DEBUG(DEBUG_ACC, "(%s-%d) ACC: x=%3.3f y=%3.3f z=%3.3f\n", __func__, __LINE__, getXAcc(), getYAcc(), getZAcc()); }
void silence_cb(int fd, short what, void *ctx) { _DEBUG("Testing for infinite silence\n"); if ( time(NULL) - last_message_timestamp > max_silence_time.tv_sec ) { _DEBUG("Things are too quiet... time to quit!\n"); fprintf(stderr, "Exiting: No messages recieved for %lu seconds (limit: %lu seconds)\n", (time(NULL) - last_message_timestamp), max_silence_time.tv_sec); error_cb(-127, (void *)NULL); } else { evtimer_del(&silence_ev); evtimer_set(&silence_ev, silence_cb, NULL); evtimer_add(&silence_ev, &max_silence_time); } }
static void * reader_thread (void * data) { struct neon_handle * h = data; pthread_mutex_lock (& h->reader_status.mutex); while (h->reader_status.reading) { /* Hit the network only if we have more than NEON_NETBLKSIZE of free buffer */ if (NEON_NETBLKSIZE < free_rb_locked (& h->rb)) { pthread_mutex_unlock (& h->reader_status.mutex); FillBufferResult ret = fill_buffer (h); pthread_mutex_lock (& h->reader_status.mutex); /* Wake up main thread if it is waiting. */ pthread_cond_broadcast (& h->reader_status.cond); if (ret == FILL_BUFFER_ERROR) { _ERROR ("<%p> Error while reading from the network. " "Terminating reader thread", (void *) h); h->reader_status.status = NEON_READER_ERROR; pthread_mutex_unlock (& h->reader_status.mutex); return NULL; } else if (ret == FILL_BUFFER_EOF) { _DEBUG ("<%p> EOF encountered while reading from the network. " "Terminating reader thread", (void *) h); h->reader_status.status = NEON_READER_EOF; pthread_mutex_unlock (& h->reader_status.mutex); return NULL; } } else { /* Not enough free space in the buffer. * Sleep until the main thread wakes us up. */ pthread_cond_wait (& h->reader_status.cond, & h->reader_status.mutex); } } _DEBUG ("<%p> Reader thread terminating gracefully", h); h->reader_status.status = NEON_READER_TERM; pthread_mutex_unlock (& h->reader_status.mutex); return NULL; }
static void buffered_socket_connect_cb(int revents, void *arg) { struct BufferedSocket *buffsock = (struct BufferedSocket *)arg; int error; socklen_t errsz = sizeof(error); if (revents & EV_TIMEOUT) { _DEBUG("%s: connection timeout for \"%s:%d\" on %d\n", __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd); buffered_socket_close(buffsock); return; } if (getsockopt(buffsock->fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errsz) == -1) { _DEBUG("%s: getsockopt failed for \"%s:%d\" on %d\n", __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd); buffered_socket_close(buffsock); return; } if (error) { _DEBUG("%s: \"%s\" for \"%s:%d\" on %d\n", __FUNCTION__, strerror(error), buffsock->address, buffsock->port, buffsock->fd); buffered_socket_close(buffsock); return; } _DEBUG("%s: connected to \"%s:%d\" on %d\n", __FUNCTION__, buffsock->address, buffsock->port, buffsock->fd); buffsock->state = BS_CONNECTED; // setup the read io watcher buffsock->read_ev.data = buffsock; ev_init(&buffsock->read_ev, buffered_socket_read_cb); ev_io_set(&buffsock->read_ev, buffsock->fd, EV_READ); // setup the write io watcher buffsock->write_ev.data = buffsock; ev_init(&buffsock->write_ev, buffered_socket_write_cb); ev_io_set(&buffsock->write_ev, buffsock->fd, EV_WRITE); // kick off the read events ev_io_start(buffsock->loop, &buffsock->read_ev); if (buffsock->connect_callback) { (*buffsock->connect_callback)(buffsock, buffsock->cbarg); } }
void OnConnect() { _DEBUG("%s\n", __FUNCTION__); onConnectCallback(); classdConnectionState = TRUE; }
int32_t initClassd(const int32_t mode, const classdInitParams_t *c) { int32_t rc = 0; pthread_mutex_lock(&classdMutex); if ( classdInited == TRUE ){ pthread_mutex_unlock(&classdMutex); return RESULT_FAILURE; } onReceiveCallBack = (onreceiveCb_t)c->ci_onReceiveCb; onCriticalErrorCallBack = (onCriticalErrorCb_t)c->ci_onCritErrorCb; onSendCompleteCallback = (onSendCompleteCb_t)c->ci_onSendCompleteCb; onConnectCallback = (onConnectCb_t )c->ci_onConnectCb; onDisconnectCallback = (onDisconnectCb_t)c->ci_onDisconnectCb; if ( mode == MODE_CLIENT ){ classdMode = mode; rc = ClientSide(c); } else if ( mode == MODE_SERVER ){ classdMode = mode; rc = ServerSide(c); } else { _DEBUG("%s: Invalid mode('%d') specified for classd", __FUNCTION__, mode); return 1; } if( rc == 0 ) classdInited = TRUE; pthread_mutex_unlock(&classdMutex); return 0; }
void ClassD::OnCriticalError(const std::string& what) { _DEBUG("%s\n", __FUNCTION__); onCriticalErrorCallBack(); return; }
static int server_auth_callback (void * userdata, const char * realm, int attempt, char * username, char * password) { struct neon_handle * h = userdata; if (! h->purl->userinfo || ! h->purl->userinfo[0]) { _ERROR ("Authentication required, but no credentials set"); return 1; } char * * authtok = g_strsplit (h->purl->userinfo, ":", 2); if (strlen (authtok[1]) > NE_ABUFSIZ - 1 || strlen (authtok[0]) > NE_ABUFSIZ - 1) { _ERROR ("Username/Password too long"); g_strfreev (authtok); return 1; } g_strlcpy (username, authtok[0], NE_ABUFSIZ); g_strlcpy (password, authtok[1], NE_ABUFSIZ); _DEBUG ("Authenticating: Username: %s, Password: %s", username, password); g_strfreev (authtok); return attempt; }
Timer::~Timer() { if (nullptr != id_) { if (0 != timer_delete(id_)) { _DEBUG("%s\n", "Not a valid POSIX timer id"); } } }
static void add_icy (struct icy_metadata * m, char * name, char * value) { if (neon_strcmp (name, "StreamTitle")) { _DEBUG ("Found StreamTitle: %s", value); g_free (m->stream_title); m->stream_title = g_strdup (value); } if (neon_strcmp (name, "StreamUrl")) { _DEBUG ("Found StreamUrl: %s", value); g_free (m->stream_url); m->stream_url = g_strdup (value); } }
int FileAction::onOpenRead(ServerContext& ctxt, FileServer& server, handle_t **handle, const char *path) { int status = 0; if (!canRead(ctxt, server, path)) { return -EPERM; } *handle = ctxt.getSession().createHandle(HDL_FILE); TAG_HANDLE(*handle); _DEBUG("onOpenRead: created handle for %s", path); if (*handle == NULL) { return -EIO; } HANDLE_PATH(**handle) = path; (*handle)->h_special_data = true; (*handle)->h_action = this; status = onRead(ctxt, server, translate(path).c_str(), HANDLE_CONTENTS(**handle)); if (status >= 0) { status = 0; (*handle)->h_count = status; } return status; }
// If this object is a suspended application, then force it. Obj* _force (Obj* obj) { _DEBUG(_lintObjPtr (obj, _ddcHeapBase, _ddcHeapMax)); _PROFILE_APPLY (forceCount++); _ENTER(1); _S(0) = obj; // Keep forcing suspensions and following indirections // until we get a real object. again: switch (_getObjTag (_S(0))) { case _tagSusp: _S(0) = _forceStep (_S(0)); goto again; case _tagIndir: _S(0) = ((SuspIndir*)_S(0)) ->obj; goto again; } Obj* tmp = _S(0); _LEAVE(1); return tmp; }
string FileAction::translate(const string path, const char *xlate) { string dir; dir_name(path.c_str(), dir); if (xlate == NULL && !m_path.empty()) { xlate = m_path.c_str(); } if (xlate) { if (xlate == string("..")) { //_DEBUG("FA::Xlate: %s => %s", path.c_str(), dir.c_str()); return dir; } if (*xlate == SEPARATOR) { dir = xlate; } else { dir += SEPSTR + xlate; } } else { dir = path; } _DEBUG("FA::Xlate: %s => %s", path.c_str(), dir.c_str()); ASSERT(dir.length()); ASSERT(base_name(dir.c_str())[0] != ':'); return dir; }
void OnDisconnect() { _DEBUG("%s\n", __FUNCTION__); onDisconnectCallback(); classdConnectionState = FALSE; }
static void buffered_socket_read_cb(EV_P_ struct ev_io *w, int revents) { struct BufferedSocket *buffsock = (struct BufferedSocket *)(w->data); int res; res = buffer_read_fd(buffsock->read_buf, w->fd); _DEBUG("%s: %d bytes read\n", __FUNCTION__, res); if (res == -1) { if (errno == EAGAIN || errno == EINTR) { return; } goto error; } else if (res == 0) { goto error; } // client's responsibility to drain the buffer if (buffsock->read_callback) { (*buffsock->read_callback)(buffsock, buffsock->read_buf, buffsock->cbarg); } if (buffsock->read_bytes_n && (BUFFER_HAS_DATA(buffsock->read_buf) >= buffsock->read_bytes_n)) { ev_timer_start(buffsock->loop, &buffsock->read_bytes_timer_ev); } return; error: if (buffsock->error_callback) { (*buffsock->error_callback)(buffsock, buffsock->cbarg); } buffered_socket_close(buffsock); }
int ShellServer::readDir(ServerContext& s, const char *dir, void *dirp, map<string, file_stat_t*>& files, bool& eof) { string_list_t args; string name; string_map_t env = s.getEnv(); process_io_t io; args.push_back(dir); int status = caller(s, "list", args, env, io); _DEBUG("read_dir: %s", io.output.c_str()); if (status >= 0) { status = bufferToFileStat(io.output.c_str(), (int) io.output.length(), files, name); } if (status < 0 && files.size() > 0) { for (map<string, file_stat_t*>::iterator it = files.begin(); it != files.end(); it++) { delete it->second; it->second = NULL; } files.clear(); } eof = true; return status; }
static void buffered_socket_write_cb(EV_P_ struct ev_io *w, int revents) { struct BufferedSocket *buffsock = (struct BufferedSocket *)(w->data); int res; res = buffer_write_fd(buffsock->write_buf, w->fd); _DEBUG("%s: %d written, left to write %lu\n", __FUNCTION__, res, BUFFER_HAS_DATA(buffsock->write_buf)); if (!BUFFER_HAS_DATA(buffsock->write_buf)) { ev_io_stop(buffsock->loop, &buffsock->write_ev); } if (res == -1) { if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS) { return; } goto error; } else if (res == 0) { goto error; } if (buffsock->write_callback) { (*buffsock->write_callback)(buffsock, buffsock->cbarg); } return; error: if (buffsock->error_callback) { (*buffsock->error_callback)(buffsock, buffsock->cbarg); } buffered_socket_close(buffsock); }
/** * Methode virtuelle qui formate les donnees du buffer circulaire en donnee * @return La donnee recu (le type doit être obligatoirement messageAsservissement) * @see getData() * @see isDataAvailable() */ boost::any RS232Sensor::onReceive() { if(!this->isDataAvailable()) _DEBUG("Pas de donnée disponible...", WARNING); // A remplacer par une vraie excpetion //boost::interprocess::scoped_lock<boost::mutex> lock(a_mutex, boost::interprocess::try_to_lock); this->a_mutex.lock(); // On protege les donnees (a_buffer, a_bufferWriteCursor, a_bufferReadCursor) messageSensor sensor_msg; this->a_buffer >> sensor_msg.id; // Recuperation de l'identifiant this->a_buffer >> sensor_msg.id_sensor; // Recuperation de l'identifiant capteur sensor_msg.time.setData(this->a_buffer.get(), 0); // Recuperation du temps sensor_msg.time.setData(this->a_buffer.get(), 1); for(int i = 0; i < a_sensors.getSensor(sensor_msg.id_sensor).getSize(); i++) // Recuperation de la donnee sensor_msg.data.setData(this->a_buffer.get(), i); sensor_msg.crc.setData(this->a_buffer.get(), 0); // Recuperation du crc sensor_msg.crc.setData(this->a_buffer.get(), 1); this->a_mutex.unlock(); // On deverouille le mutex boost::any msg = sensor_msg; return msg; // retourne un messaage asservissement }
// ------ Ref Obj* primRefUpdate (Obj* ref_, Obj* x_) { _DEBUG (assert (_getObjTag(ref_) == _tagBase)); _ENTER(2); _S(0) = ref_; _S(1) = x_; // unboxing. DataM* refDataM; Data* refData; int objType = _objType(_S(0)); switch (objType) { case _ObjTypeDataM: refDataM = (DataM*) _force(_S(0)); Obj*** payload = (Obj***)refDataM ->payload; *payload[1] = _S(1); break; case _ObjTypeData: refData = (Data*) _force(_S(0)); refData->a[0] = _S(1); break; default: _PANIC("Updating Ref with unknown internal object type"); break; } _LEAVE(2); return _primUnit; }