+
+ /* Add per scheduler context */
+ if (!silc_hash_table_find(engine->contexts, schedule, NULL,
+ (void *)&ps->sc)) {
+ ps->sc = silc_calloc(1, sizeof(*ps->sc));
+ if (!ps->sc) {
+ silc_packet_stream_destroy(ps);
+ silc_mutex_unlock(engine->lock);
+ return NULL;
+ }
+ ps->sc->engine = engine;
+ ps->sc->schedule = schedule;
+
+ /* Allocate data input buffer */
+ tmp = silc_malloc(SILC_PACKET_DEFAULT_SIZE * 31);
+ if (!tmp) {
+ silc_free(ps->sc);
+ ps->sc = NULL;
+ silc_packet_stream_destroy(ps);
+ silc_mutex_unlock(engine->lock);
+ return NULL;
+ }
+ silc_buffer_set(&ps->sc->inbuf, tmp, SILC_PACKET_DEFAULT_SIZE * 31);
+ silc_buffer_reset(&ps->sc->inbuf);
+
+ /* Add to per scheduler context hash table */
+ if (!silc_hash_table_add(engine->contexts, schedule, ps->sc)) {
+ silc_buffer_purge(&ps->sc->inbuf);
+ silc_free(ps->sc);
+ ps->sc = NULL;
+ silc_packet_stream_destroy(ps);
+ silc_mutex_unlock(engine->lock);
+ return NULL;
+ }
+ }
+ ps->sc->stream_count++;
+
+ /* Add the packet stream to engine */