Permalink
Browse files

ring buffer

  • Loading branch information...
1 parent fdc23c1 commit 22f0e5223ab25a07b92141c812b1e62369b757f3 @xaqq committed Apr 17, 2012
Showing with 48 additions and 25 deletions.
  1. +5 −4 Makefile
  2. +3 −2 includes/ring_buffer.h
  3. +2 −19 src/ring_buffer/ring_buffer.c
  4. +38 −0 src/ring_buffer/ring_buffer_read.c
View
9 Makefile
@@ -1,11 +1,11 @@
##
## Makefile for in /home/xaqq/Documents/network
-##
+##
## Made by arnaud kapp
## Login <kapp_a@epitech.net>
-##
+##
## Started on Tue Feb 14 18:18:42 2012 arnaud kapp
-## Last update Tue Apr 3 16:23:53 2012 arnaud kapp
+## Last update Tue Apr 17 17:26:09 2012 arnaud kapp
##
NAME= libmynet.so
@@ -20,7 +20,8 @@ SRC= src/tcpsrv.c \
src/ring_buffer/ring_buffer_st.c \
src/flags.c \
src/epoll_manager.c \
- src/write.c
+ src/write.c \
+ src/ring_buffer/ring_buffer_read.c
OBJ= $(SRC:.c=.o)
View
5 includes/ring_buffer.h
@@ -5,20 +5,21 @@
** Login <kapp_a@epitech.net>
**
** Started on Wed Feb 22 21:32:42 2012 arnaud kapp
-** Last update Sun Apr 8 19:05:10 2012 arnaud kapp
+** Last update Tue Apr 17 17:18:18 2012 arnaud kapp
*/
#ifndef RINGBUFFER_H
# define RINGBUFFER_H
# define RGBUF_SIZE 2048
-typedef struct s_ring_buff
+typedef struct s_ring_buff
{
unsigned char *data;
int size;
int s; //start
int e; //end
+ int last_start;
} t_ring_buff;
typedef t_ring_buff t_ring_buff;
View
21 src/ring_buffer/ring_buffer.c
@@ -5,7 +5,7 @@
** Login <kapp_a@epitech.net>
**
** Started on Wed Feb 22 21:48:40 2012 arnaud kapp
-** Last update Thu Apr 5 15:09:25 2012 arnaud kapp
+** Last update Tue Apr 17 17:22:21 2012 arnaud kapp
*/
#include <stdlib.h>
@@ -33,6 +33,7 @@ static int resize(t_ring_buff *b)
return (0);
memcpy(ptr, tmp, r);
b->s = 0;
+ b->last_start = 0;
b->e = r;
b->data = ptr;
b->size += RGBUF_SIZE;
@@ -89,21 +90,3 @@ int rgbuf_write(t_ring_buff *b, unsigned char *d, int s)
}
return (0);
}
-
-int rgbuf_read(t_ring_buff *b, unsigned char *d, int s)
-{
- int direct;
-
- if (s > rgbuf_r_available(b))
- s = rgbuf_r_available(b);
-
- direct = b->size - b->s;
- direct = direct > s ? s : direct;
- memcpy(d, b->data + b->s, direct);
- s -= direct;
- b->s += direct;
- b->s %= b->size;
- if (s)
- rgbuf_read(b, d + direct, s);
- return (s);
-}
View
38 src/ring_buffer/ring_buffer_read.c
@@ -0,0 +1,38 @@
+/*
+** ring_buffer_read.c for in /home/xaqq/Documents/net
+**
+** Made by arnaud kapp
+** Login <kapp_a@epitech.net>
+**
+** Started on Tue Apr 17 17:22:07 2012 arnaud kapp
+** Last update Tue Apr 17 17:26:40 2012 arnaud kapp
+*/
+
+#include <stdlib.h>
+#include <strings.h>
+#include <string.h>
+#include <stdio.h>
+#include "ring_buffer.h"
+
+static int read_i(t_ring_buff *b, unsigned char *d, int s)
+{
+ int direct;
+
+ if (s > rgbuf_r_available(b))
+ s = rgbuf_r_available(b);
+ direct = b->size - b->s;
+ direct = direct > s ? s : direct;
+ memcpy(d, b->data + b->s, direct);
+ s -= direct;
+ b->s += direct;
+ b->s %= b->size;
+ if (s)
+ read_i(b, d + direct, s);
+ return (s);
+}
+
+int rgbuf_read(t_ring_buff *b, unsigned char *d, int s)
+{
+ b->last_start = b->s;
+ return (read_i(b, d, s));
+}

0 comments on commit 22f0e52

Please sign in to comment.