/* * Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. * $Id: ctrlfd.h,v 1.6 2004/08/30 02:49:16 bcrl Exp $ * Released under the GNU Public License. See LICENSE file for details. */ #include #ifndef CTRLFD_H #define CTRLFD_H #ifndef BABD_H #include "babd.h" #endif #include "selectops.h" #include struct sockaddr_in; class ctrlfd_t; class ctrlfd_die_listener { public: virtual void ctrlfd_die_notification(ctrlfd_t *cfd) { return; } virtual ~ctrlfd_die_listener() { return; } }; class ctrlfd_t : public SelectEventHandler { public: unsigned c_pos; int c_err; char c_buf[4096]; ctrlfd_die_listener *c_die_notify; int c_fd; unsigned c_last_was_nl : 1, c_in_init : 1; ctrlfd_t **c_ptr; ctrlfd_t(int fd=-1, int in_init=0) { c_fd = fd; c_pos = 0; c_err = 0; c_die_notify = 0; c_ptr = 0; c_last_was_nl = 1; c_in_init = in_init; } ~ctrlfd_t() { ctrlfd_die_listener *notify = c_die_notify; c_die_notify = 0; if (notify) notify->ctrlfd_die_notification(this); if (c_fd >= 0) { SelectSetEvents(c_fd, SEL_NONE); if (!c_in_init) close(c_fd); } c_fd = -1; if (c_ptr) *c_ptr = NULL; c_ptr = NULL; } void die_notify(ctrlfd_die_listener *notify) { if (c_die_notify) *(char *)0 = 0; c_die_notify = notify; } void die_unnotify(ctrlfd_die_listener *notify) { if (c_die_notify == notify) c_die_notify = 0; } void clear_events(void) { SelectSetEvents(c_fd, SEL_NONE); } void SelectEvent(int fd, SelectEventType event); void printf(const char *fmt, ...) __attribute__((format(printf, 2, 3))); void perror(const char *fmt, ...) __attribute__((format(printf, 2, 3))); void printsin(const struct sockaddr_in *sin); void done(int rc); void my_putchar(char ch); void dump(ctrlfd_t *dst) { dst->printf("cfd(%d)", c_fd); // FIXME: dump call hook } void unlinkme(ctrlfd_t **ptr) { c_ptr = ptr; } void dfs_print_bytes(const char *name, unsigned char *bytes, size_t len); }; #endif