Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ring buffer

  • Loading branch information...
commit 22f0e5223ab25a07b92141c812b1e62369b757f3 1 parent fdc23c1
KAPP Arnaud authored
9 Makefile
... ... @@ -1,11 +1,11 @@
1 1 ##
2 2 ## Makefile for in /home/xaqq/Documents/network
3   -##
  3 +##
4 4 ## Made by arnaud kapp
5 5 ## Login <kapp_a@epitech.net>
6   -##
  6 +##
7 7 ## Started on Tue Feb 14 18:18:42 2012 arnaud kapp
8   -## Last update Tue Apr 3 16:23:53 2012 arnaud kapp
  8 +## Last update Tue Apr 17 17:26:09 2012 arnaud kapp
9 9 ##
10 10
11 11 NAME= libmynet.so
@@ -20,7 +20,8 @@ SRC= src/tcpsrv.c \
20 20 src/ring_buffer/ring_buffer_st.c \
21 21 src/flags.c \
22 22 src/epoll_manager.c \
23   - src/write.c
  23 + src/write.c \
  24 + src/ring_buffer/ring_buffer_read.c
24 25
25 26 OBJ= $(SRC:.c=.o)
26 27
5 includes/ring_buffer.h
@@ -5,7 +5,7 @@
5 5 ** Login <kapp_a@epitech.net>
6 6 **
7 7 ** Started on Wed Feb 22 21:32:42 2012 arnaud kapp
8   -** Last update Sun Apr 8 19:05:10 2012 arnaud kapp
  8 +** Last update Tue Apr 17 17:18:18 2012 arnaud kapp
9 9 */
10 10
11 11 #ifndef RINGBUFFER_H
@@ -13,12 +13,13 @@
13 13
14 14 # define RGBUF_SIZE 2048
15 15
16   -typedef struct s_ring_buff
  16 +typedef struct s_ring_buff
17 17 {
18 18 unsigned char *data;
19 19 int size;
20 20 int s; //start
21 21 int e; //end
  22 + int last_start;
22 23 } t_ring_buff;
23 24
24 25 typedef t_ring_buff t_ring_buff;
21 src/ring_buffer/ring_buffer.c
@@ -5,7 +5,7 @@
5 5 ** Login <kapp_a@epitech.net>
6 6 **
7 7 ** Started on Wed Feb 22 21:48:40 2012 arnaud kapp
8   -** Last update Thu Apr 5 15:09:25 2012 arnaud kapp
  8 +** Last update Tue Apr 17 17:22:21 2012 arnaud kapp
9 9 */
10 10
11 11 #include <stdlib.h>
@@ -33,6 +33,7 @@ static int resize(t_ring_buff *b)
33 33 return (0);
34 34 memcpy(ptr, tmp, r);
35 35 b->s = 0;
  36 + b->last_start = 0;
36 37 b->e = r;
37 38 b->data = ptr;
38 39 b->size += RGBUF_SIZE;
@@ -89,21 +90,3 @@ int rgbuf_write(t_ring_buff *b, unsigned char *d, int s)
89 90 }
90 91 return (0);
91 92 }
92   -
93   -int rgbuf_read(t_ring_buff *b, unsigned char *d, int s)
94   -{
95   - int direct;
96   -
97   - if (s > rgbuf_r_available(b))
98   - s = rgbuf_r_available(b);
99   -
100   - direct = b->size - b->s;
101   - direct = direct > s ? s : direct;
102   - memcpy(d, b->data + b->s, direct);
103   - s -= direct;
104   - b->s += direct;
105   - b->s %= b->size;
106   - if (s)
107   - rgbuf_read(b, d + direct, s);
108   - return (s);
109   -}
38 src/ring_buffer/ring_buffer_read.c
... ... @@ -0,0 +1,38 @@
  1 +/*
  2 +** ring_buffer_read.c for in /home/xaqq/Documents/net
  3 +**
  4 +** Made by arnaud kapp
  5 +** Login <kapp_a@epitech.net>
  6 +**
  7 +** Started on Tue Apr 17 17:22:07 2012 arnaud kapp
  8 +** Last update Tue Apr 17 17:26:40 2012 arnaud kapp
  9 +*/
  10 +
  11 +#include <stdlib.h>
  12 +#include <strings.h>
  13 +#include <string.h>
  14 +#include <stdio.h>
  15 +#include "ring_buffer.h"
  16 +
  17 +static int read_i(t_ring_buff *b, unsigned char *d, int s)
  18 +{
  19 + int direct;
  20 +
  21 + if (s > rgbuf_r_available(b))
  22 + s = rgbuf_r_available(b);
  23 + direct = b->size - b->s;
  24 + direct = direct > s ? s : direct;
  25 + memcpy(d, b->data + b->s, direct);
  26 + s -= direct;
  27 + b->s += direct;
  28 + b->s %= b->size;
  29 + if (s)
  30 + read_i(b, d + direct, s);
  31 + return (s);
  32 +}
  33 +
  34 +int rgbuf_read(t_ring_buff *b, unsigned char *d, int s)
  35 +{
  36 + b->last_start = b->s;
  37 + return (read_i(b, d, s));
  38 +}

0 comments on commit 22f0e52

Please sign in to comment.
Something went wrong with that request. Please try again.