-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.h
66 lines (49 loc) · 1011 Bytes
/
conn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef CONN_H
#define CONN_H
#include<stdio.h>
#include<errno.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/un.h>
#include<sys/types.h>
#include<sys/socket.h>
/******* VARIABILI GLOBALI *******/
#define SOCKNAME "./objstore.sock" //nome socket
/******* STRUCT *******/
typedef struct msg{
int len;
char* buff;
}msg_t;
/******* FUNZIONI *******/
static inline int writen(long fd, void *buff, size_t size){
int r;
size_t left=size;
char *bufptr=(char*)buff;
while(left>0){
if((r=write((int)fd,bufptr,left))==-1){
if(errno==EINTR) continue;
return -1;
}
if(r==0) return 0;
left-=r;
bufptr+=r;
}
return 1;
}
static inline int readn(long fd, void *buff, size_t size){
int r;
int left=size;
char *bufptr=(char*)buff;
while(left>0){
if((r=read((int)fd,bufptr,size))==-1){
if(errno==EINTR) continue;
return -1;
}
if(r==0) return 0;
left-=r;
bufptr+=r;
}
return size;
}
#endif