Example #1
0
void glk_fileref_destroy(frefid_t fileref) {
  if (dispatch_unregister) {
    dispatch_unregister(fileref, gidisp_Class_Fileref, fileref->dispatch_rock);
  }
  free(fileref->name);
  free(fileref);
}
Example #2
0
File: mqtt.c Project: dsmrd/dsmrd
static void on_disconnect(/*@unused@*/ struct mosquitto *mosq, void *obj, /*@unused@*/ int rc) {
    mqtt_t inst = (mqtt_t) obj;
    int rval;

    info("MQTT disconnect: %s", (rc == 0) ? "Client disconnected" : "Unexpected disconnect");

    rval = dispatch_unregister(inst->dispatch, inst);
    assert(rval == 0);

    inst->connected = 0;
}
Example #3
0
/* http://www.eblong.com/zarf/glk/glk-spec-070_5.html#s.3 */
void glk_stream_close(strid_t str, stream_result_t *result) {
  printf("DEBUG: glk_stream_close stream=%p\n", str);

  /* We don't currently track these. */
  if (result) {
    result->readcount = str->readcount;
    result->writecount = str->writecount;
  }

  /* remove stream from linked list */
  if (!first_stream) {
    printf("WTF, closing stream when first_stream==NULL (not even on it ourselves?)\n");
    exit(32);
  } else if (first_stream == str) {
    printf("We were the only stream, setting first_stream to it's next\n");
    first_stream = first_stream->next;
  } else {
    strid_t candidate = first_stream;
    printf("DEBUG: In the hard case, starting with %p\n", candidate);
    while (candidate->next != str) {
      printf("DEBUG: in close_stream of %p, candidate=%p, next=%p\n", str, candidate, candidate->next);
      candidate = candidate->next;
    }
    printf("DEBUG: Found ourselves after %p\n", candidate);
    candidate->next = str->next;
  }

  /* FIXME: This probably belongs in stream_memory.c */
  if (str->type == STREAM_TYPE_MEMORY && dispatch_disown) {
    printf("DEBUG: (close_stream) width %d, buflen=%d\n", str->u.mem.width, str->u.mem.buflen);
    if (str->u.mem.width == 4) {
      dispatch_disown(str->u.mem.buf, str->u.mem.buflen, "&+#!Iu", str->u.mem.buffer_adoption_rock);
    } else if (str->u.mem.width == 1) {
      dispatch_disown(str->u.mem.buf, str->u.mem.buflen, "&+#!Cn", str->u.mem.buffer_adoption_rock);
    } else {
      printf("(close_stream) Width %d, not 1 or 4\n", str->u.mem.width);
      exit(22);
    }
  }

  /* We should probably do some sort of cleanup here, and disown the
     buffer, in the case of a memory stream. */
  if (dispatch_unregister) {
    dispatch_unregister((void *)str, gidisp_Class_Stream, str->dispatch_rock);
  }

  /* Curses likes to write to a closed window stream. */
  free(str);
}