-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.c
97 lines (84 loc) · 2.54 KB
/
delete.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "client.h"
#include "delete.h"
void deletes(char **command)
{
int storage_socket;
struct sockaddr_in nm_addr;
socklen_t nm_addr_size;
storage_socket = socket(AF_INET, SOCK_STREAM, 0);
if (storage_socket < 0)
{
perror("Error in storage server socket creation");
exit(1);
}
nm_addr.sin_family = AF_INET;
nm_addr.sin_port = htons(NM_PORT);
nm_addr.sin_addr.s_addr = inet_addr(NM_SERVER_IP);
if (connect(storage_socket, (struct sockaddr *)&nm_addr, sizeof(nm_addr)) < 0)
{
perror("Error in connecting to the naming server");
close(storage_socket);
exit(1);
}
printf("Connected to the naming server\n");
struct timeval timeout1;
timeout1.tv_sec = 1;
timeout1.tv_usec = 0;
if (setsockopt(storage_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout1, sizeof(timeout1)) < 0)
{
perror("setsockopt for receive timeout");
close(storage_socket);
}
// Example: Attempt to receive data with a timeout
char buffer1[1024];
ssize_t bytesRead1;
bytesRead1 = recv(storage_socket, buffer1, sizeof(buffer1), 0);
if (bytesRead1 == -1)
{
if (errno == EAGAIN || errno == EWOULDBLOCK)
{
printf("Receive operation timed out.\n");
}
else
{
perror("recv");
}
}
else
{
printf("Received acknowledgment from naming server operation successful: %s\n", buffer1);
}
char command3[1024];
strcpy(command3, command[0]);
strcat(command3, " ");
strcat(command3, command[1]);
send(storage_socket, command3, strlen(command3), 0);
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (setsockopt(storage_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
{
perror("setsockopt for receive timeout");
close(storage_socket);
}
// Example: Attempt to receive data with a timeout
char buffer[1024];
ssize_t bytesRead;
bytesRead = recv(storage_socket, buffer, sizeof(buffer), 0);
if (bytesRead == -1)
{
if (errno == EAGAIN || errno == EWOULDBLOCK)
{
printf("Receive operation timed out.\n");
}
else
{
perror("recv");
}
}
else
{
printf("Received acknowledgment from naming server operation successful: %s\n", buffer);
}
close(storage_socket);
}