コード例 #1
0
static THREAD_FUNC LissThread(void *argptr)
{
ISIDL_PAR *par;
NRTS_DL *nrts;
LISS *liss = NULL;
LOCALPKT local;
LISS_PKT pkt;
int RetryInterval = INITIAL_RETRY_INTERVAL;
UINT32 flags = 0;
static char *fid = "LissThread";

    par = (ISIDL_PAR *) argptr;

    MUTEX_INIT(&local.mutex);
    local.dl = par->dl[0];
    strlcpy(local.raw.hdr.site, local.dl->sys->site, ISI_SITELEN+1);
    local.raw.hdr.desc.comp = ISI_COMP_NONE;;
    local.raw.hdr.desc.type = ISI_TYPE_MSEED;
    local.raw.hdr.desc.size = 1;
    local.raw.hdr.len.used = blksiz;
    local.raw.hdr.len.native = blksiz;

    while (1) {

    /* Connect to server, if necessary */

        while (liss == NULL) {
            if ((liss = lissOpen(server, port, blksiz, to, par->lp)) == NULL) {
                sleep(RetryInterval);
                RetryInterval *= 2;
                if (RetryInterval > MAX_RETRY_INTERVAL) RetryInterval = INITIAL_RETRY_INTERVAL;
            } else {
                LogMsg(LOG_INFO, "connected to liss@%s:%d, blksiz=%d, to=%d", server, port, blksiz, to);
                local.raw.payload = liss->buf;
            }
        }

    /* Read next packet */

        if (lissRead(liss, &pkt, flags)) {
            RetryInterval = INITIAL_RETRY_INTERVAL;
            if (par->first[0]) {
                LogMsg(LOG_INFO, "initial %s packet received", local.dl->sys->site);
                par->first[0] = FALSE;
            }
            local.raw.hdr.desc.order = (pkt.fsdh.order == BIG_ENDIAN_BYTE_ORDER) ? ISI_ORDER_BIGENDIAN : ISI_ORDER_LTLENDIAN;
            ProcessLocalData(&local);
        } else {
            LogMsg(LOG_INFO, "liss@%s:%d: lissRead: %s", server, port, strerror(errno));
            liss = lissClose(liss);
        }
    }
}
コード例 #2
0
static void StuffSample(BAROMETER *bp, ISIDL_TIMESTAMP *ttag, INT32 value)
{
char timestring[32];
static char *fid = "qdplus:StuffSample";

/* Since there are some startup delays in the barometer reading thread,
 * we will discard all "missed" samples until we've seen one valid
 * sample come through here.  That will prevent the first packet from
 * having a couple of unwarrented "missed" samples at the front.
 */

    if (!bp->ValidSampleSeen) {
        if (value == MISSED_BAROMETER_SAMPLE) {
            return;
        } else {
            bp->ValidSampleSeen = TRUE;
        }
    }

    if (bp->nsamp == 0) {
        InsertQdplusSerialno(&bp->local.raw, bp->format.qdplus.serialno);
        bp->out = StartPacket(&bp->local.raw, ttag, bp);
    }

    bp->out[bp->nsamp++] = htonl(value);

    if (BarometerDebugEnabled()) {
        utilLttostr(ttag->sys, 0, timestring);
        LogMsg(LOG_INFO, "%s %3d/%d: %s %ld\n", bp->param.sn, bp->nsamp, bp->maxsamp, timestring, value);
    }

    if (bp->nsamp == bp->maxsamp) {
        FinishPacket(&bp->local.raw, (UINT16) bp->nsamp, ttag);
        bp->nsamp = 0;
        ProcessLocalData(&bp->local);
    }
}
コード例 #3
0
status_t
AbstractSingleFileServerProcess::RunInternal()
{
	if (Logger::IsInfoEnabled())
		printf("[%s] will fetch data\n", Name());

	BPath localPath;
	status_t result = GetLocalPath(localPath);

	if (result != B_OK)
		return result;

	BString urlPathComponent = UrlPathComponent();

	if (IsSuccess(result) && HasOption(SERVER_PROCESS_DROP_CACHE))
		result = DeleteLocalFile(localPath);

	bool hasData = false;
	off_t size;

	if (IsSuccess(result))
		result = StorageUtils::ExistsObject(localPath, &hasData, NULL, &size);

	hasData = hasData && size > 0;

	if (IsSuccess(result) && ShouldAttemptNetworkDownload(hasData)) {
		result = DownloadToLocalFileAtomically(
			localPath,
			ServerSettings::CreateFullUrl(urlPathComponent));

		if (!IsSuccess(result)) {
			if (hasData) {
				printf("[%s] failed to update data, but have old data "
					"anyway so carry on with that\n", Name());
				result = B_OK;
			} else {
				printf("[%s] failed to obtain data\n", Name());
			}
		} else {
			if (Logger::IsInfoEnabled())
				printf("[%s] did fetch data\n", Name());
		}
	}

	if (IsSuccess(result)) {
		status_t hasDataResult = StorageUtils::ExistsObject(
			localPath, &hasData, NULL, &size);

		hasData = hasData && size > 0;

		if (hasDataResult == B_OK && !hasData)
			result = HD_ERR_NO_DATA;
	}

	if (IsSuccess(result)) {
		printf("[%s] will process data\n", Name());
		result = ProcessLocalData();

		switch (result) {
			case B_OK:
				printf("[%s] did process data\n", Name());
				break;
			default:
				MoveDamagedFileAside(localPath);
				break;
		}
	}

	return result;
}