nw_channelWriter nw_channelWriterNew( const char *serviceName, const char *pathName, nw_sendChannel sendChannel, u_networkReader reader, c_ulong stat_channel_id) { nw_channelWriter result = NULL; c_ulong queueSize; c_ulong priority; c_bool reliable; c_bool useAsDefault; static c_bool defaultDefined = FALSE; u_result ures; c_ulong resolutionMsecs; c_time resolution; char *tmpPath; size_t tmpPathSize; char* name; result = (nw_channelWriter)os_malloc((os_uint32)sizeof(*result)); if (result != NULL) { /* Initialize parent */ /* First determine its parameter path */ tmpPathSize = strlen(pathName) + strlen(NWCF_SEP) + strlen(NWCF_ROOT(Tx)) + strlen(NWCF_SEP) + strlen(NWCF_ROOT(Scheduling)) + 1 /* '\0' */; tmpPath = os_malloc(tmpPathSize); os_sprintf(tmpPath, "%s%s%s%s%s", pathName, NWCF_SEP, NWCF_ROOT(Tx), NWCF_SEP, NWCF_ROOT(Scheduling)); nw_channelUserInitialize((nw_channelUser)result, pathName /* use pathName as name */, tmpPath, reader, nw_channelWriterMainFunc, nw_channelWriterTrigger, nw_channelWriterFinalize); os_free(tmpPath); /* Own initialization */ result->serviceName = os_strdup(serviceName); /* Store the channel to write to */ result->sendChannel = sendChannel; /* Create a new networking queue */ /* First read the corresponding options */ queueSize = NWCF_SIMPLE_SUBPARAM(ULong, pathName, Tx, QueueSize); priority = NWCF_SIMPLE_ATTRIB(ULong, pathName, priority); reliable = NWCF_SIMPLE_ATTRIB(Bool, pathName, reliable); useAsDefault = NWCF_SIMPLE_ATTRIB(Bool, pathName, default); name = NWCF_DEFAULTED_ATTRIB(String, pathName, ChannelName,"unnamed","unnamed"); if (useAsDefault) { if (defaultDefined) { NW_REPORT_WARNING_1( "initializing network", "default channel redefined by channel \"%s\"", pathName); useAsDefault = FALSE; } else { defaultDefined = TRUE; } } result->scs = nw_SendChannelStatisticsNew(); result->stat_channel_id = stat_channel_id; resolutionMsecs = NWCF_SIMPLE_PARAM(ULong, pathName, Resolution); if (resolutionMsecs < NWCF_MIN(Resolution)) { NW_REPORT_WARNING_3( "initializing network", "Requested value %d for resolution period for channel \"%s\" is " "too small, using %d instead", resolutionMsecs, pathName, NWCF_MIN(Resolution)); resolutionMsecs = NWCF_MIN(Resolution); } resolution.seconds = resolutionMsecs/1000; resolution.nanoseconds = 1000000*(resolutionMsecs % 1000); tmpPathSize = strlen(pathName) + strlen(NWCF_SEP) + strlen(NWCF_ROOT(Tx)) + 1; tmpPath = os_malloc(tmpPathSize); os_sprintf(tmpPath, "%s%s%s", pathName, NWCF_SEP, NWCF_ROOT(Tx)); result->reportInterval = NWCF_SIMPLE_PARAM(ULong, tmpPath, ReportInterval); if (result->reportInterval < NWCF_MIN(ReportInterval)) { NW_REPORT_WARNING_3( "initializing network", "Requested report interval value %d for channel \"%s\" is " "too small, using %d instead", result->reportInterval, pathName, NWCF_MIN(ReportInterval)); result->reportInterval = NWCF_MIN(ReportInterval); } os_free(tmpPath); ures = u_networkReaderCreateQueue(reader, queueSize, priority, reliable, FALSE, resolution, useAsDefault, &result->queueId, name); os_free(name); if (ures != U_RESULT_OK) { NW_REPORT_ERROR_1( "initializing network", "creation of network queue failed for channel \"%s\"", pathName); } }
void nw_plugChannelInitialize( nw_plugChannel channel, nw_seqNr seqNr, nw_networkId nodeId, nw_communicationKind communication, nw_plugPartitions partitions, nw_userData *userDataPtr, const char *pathName, nw_onFatalCallBack onFatal, c_voidp onFatalUsrData) { nw_size fragmentLength; nw_bool reliable; nw_bool controlNeeded; static sk_portNr sendingPortNr = NWCF_DEF(PortNr); static sk_portNr receivingPortNr = NWCF_DEF(PortNr); sk_portNr newPortNr; nw_plugInterChannel *interChannelPtr = (nw_plugInterChannel *)userDataPtr; char *defaultPartitionAddress; /* Simple attributes */ channel->name = nw_stringDup(pathName); channel->Id = seqNr; channel->nodeId = nodeId; channel->communication = communication; channel->partitions = partitions; /* Attributes to be read from config */ /* QoS-es*/ reliable = NWCF_SIMPLE_ATTRIB(Bool, pathName, reliable); if (reliable) { channel->reliabilityOffered = NW_REL_RELIABLE; controlNeeded = TRUE; /* Create object for inter-channel communication */ nw_plugInterChannelIncarnate(interChannelPtr, pathName); channel->interChannelComm = *interChannelPtr; } else { channel->reliabilityOffered = NW_REL_BEST_EFFORT; controlNeeded = FALSE; /* NO object needed for inter-channel communication */ channel->interChannelComm = NULL; } /* Default, to be implemented */ channel->priorityOffered = NW_PRIORITY_UNDEFINED; channel->latencyBudgetOffered = NW_LATENCYBUDGET_UNDEFINED; /* Network fragment length */ fragmentLength = (nw_size)NWCF_SIMPLE_PARAM(Size, pathName, FragmentSize); /* CHECKME, NWCF_MIN(FragmentSize) must be larger dealing with encryption */ if (fragmentLength < NWCF_MIN(FragmentSize)) { NW_REPORT_WARNING_3("initializing network", "Channel \"%s\": requested value %u for fragment size is too small, " "using %u instead", pathName, fragmentLength, NWCF_MIN(FragmentSize)); fragmentLength = NWCF_MIN(FragmentSize); } else if(fragmentLength > NWCF_MAX(FragmentSize)) { NW_REPORT_WARNING_3("initializing network", "Channel \"%s\": requested value " PA_SIZEFMT " for fragment size is too big, " "using %u instead", pathName, fragmentLength, NWCF_MAX(FragmentSize)); fragmentLength = NWCF_MAX(FragmentSize); } /* FIXME, this rounds up to multiple of 4, but it should round down to * meet network constraints (??) */ /* round to lowest NW_FRAG_BOUNDARY multiplication higher than * fragmentLength */ channel->fragmentLength = NW_ALIGN(NW_PLUGDATABUFFER_ALIGNMENT, (nw_length)fragmentLength); /* What is the base adress of the socket wee need ? */ nw_plugPartitionsGetDefaultPartition(partitions, &defaultPartitionAddress, NULL /* SecurityProfile not of interest */ ); switch (communication) { case NW_COMM_SEND: newPortNr = NWCF_DEFAULTED_PARAM(ULong, pathName, PortNr, sendingPortNr); if (newPortNr == sendingPortNr) { sendingPortNr+=2; } channel->socket = nw_socketSendNew(defaultPartitionAddress, newPortNr, controlNeeded, pathName); break; case NW_COMM_RECEIVE: newPortNr = NWCF_DEFAULTED_PARAM( ULong, pathName, PortNr, receivingPortNr); if (newPortNr == receivingPortNr) { receivingPortNr+=2; } channel->socket = nw_socketReceiveNew(defaultPartitionAddress, newPortNr, controlNeeded, pathName); break; default: NW_CONFIDENCE(FALSE); break; } channel->messageBox = nw_messageBoxNew(); channel->onFatal = onFatal; channel->onFatalUsrData = onFatalUsrData; channel->reconnectAllowed = NWCF_SIMPLE_ATTRIB(Bool,NWCF_ROOT(General) NWCF_SEP NWCF_NAME(Reconnection),allowed); channel->crc = ut_crcNew(UT_CRC_KEY); }