lib/eggdrop/throttle.h File Reference

Go to the source code of this file.

Functions

int throttle_on (int idx)
int throttle_off (int idx)
int throttle_set (int idx, int dir, int speed)


Function Documentation

int throttle_off ( int  idx  ) 

Definition at line 171 of file throttle.c.

References throttle::buf, throttle::len, NULL, sockbuf_detach_filter(), sockbuf_isvalid(), sockbuf_on_write(), THROTTLE_LEVEL, throttle_lookup(), throttle_remove(), throttle_timer, and timer_destroy().

Referenced by throttle_on_delete().

00172 {
00173   throttle_t *t;
00174 
00175   t = throttle_lookup(idx);
00176   if (!t) return(-1);
00177 
00178   throttle_remove(t);
00179   if (sockbuf_isvalid(idx)) {
00180     sockbuf_detach_filter(idx, &throttle_filter, NULL);
00181     if (t->len) sockbuf_on_write(idx, THROTTLE_LEVEL, t->buf, t->len);
00182   }
00183 
00184   if (t->buf) free(t->buf);
00185   free(t);
00186 
00187   if (!throttle_head) {
00188     timer_destroy(throttle_timer);
00189     throttle_timer = -1;
00190   }
00191   return(0);
00192 }

int throttle_on ( int  idx  ) 

Definition at line 153 of file throttle.c.

References throttle::idx, egg_timeval::sec, sockbuf_attach_filter(), throttle_add(), throttle_secondly(), throttle_timer, timer_create_repeater, and egg_timeval::usec.

Referenced by script_net_throttle().

00154 {
00155   throttle_t *t;
00156   egg_timeval_t howlong;
00157 
00158   t = calloc(1, sizeof(*t));
00159   t->idx = idx;
00160   throttle_add(t);
00161   sockbuf_attach_filter(idx, &throttle_filter, t);
00162 
00163   if (throttle_timer < 0) {
00164     howlong.sec = 1;
00165     howlong.usec = 0;
00166     throttle_timer = timer_create_repeater(&howlong, "bandwidth throttler", throttle_secondly);
00167   }
00168   return(0);
00169 }

int throttle_set ( int  idx,
int  dir,
int  speed 
)

Definition at line 194 of file throttle.c.

References throttle::buf, throttle::len, sockbuf_on_write(), sockbuf_on_written(), throttle::speed_in, throttle::speed_out, THROTTLE_LEVEL, and throttle_lookup().

Referenced by script_net_throttle(), and script_net_throttle_set().

00195 {
00196   throttle_t *t;
00197   int r;
00198 
00199   t = throttle_lookup(idx);
00200   if (!t) return(-1);
00201   if (dir) {
00202     t->speed_out = speed;
00203     if (speed <= 0 && t->len) {
00204       r = sockbuf_on_write(idx, THROTTLE_LEVEL, t->buf, t->len);
00205       if (r > 0) sockbuf_on_written(idx, THROTTLE_LEVEL, r, t->len - r);
00206       t->len = 0;
00207     }
00208   }
00209   else t->speed_in = speed;
00210   return(0);
00211 }


Generated on Sun Nov 30 18:43:35 2008 for eggdrop1.9 by  doxygen 1.5.6