[CRIU] [PATCH 2/7] remote: Move setup_TCP_client_socket to img-proxy
Radostin Stoyanov
rstoyanov1 at gmail.com
Sun Jul 8 19:47:06 MSK 2018
The function setup_TCP_client_socket() is used only in img-proxy.c
and it makes sense to be stored there. This change will reduce the
size of img-remote.c
Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
criu/img-proxy.c | 37 +++++++++++++++++++++++++++++++++++++
criu/img-remote.c | 37 -------------------------------------
criu/include/img-remote.h | 1 -
3 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/criu/img-proxy.c b/criu/img-proxy.c
index c4d442e6..2d7d246d 100644
--- a/criu/img-proxy.c
+++ b/criu/img-proxy.c
@@ -5,9 +5,46 @@
#include "criu-log.h"
#include <pthread.h>
#include <fcntl.h>
+#include <netdb.h>
#include <sys/socket.h>
#include "cr_options.h"
+int setup_TCP_client_socket(char *hostname, int port)
+{
+ int sockfd;
+ struct sockaddr_in serv_addr;
+ struct hostent *server;
+
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ pr_perror("Unable to open remote image socket");
+ return -1;
+ }
+
+ server = gethostbyname(hostname);
+ if (server == NULL) {
+ pr_perror("Unable to get host by name (%s)", hostname);
+ goto err;
+ }
+
+ bzero((char *) &serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ bcopy((char *) server->h_addr,
+ (char *) &serv_addr.sin_addr.s_addr,
+ server->h_length);
+ serv_addr.sin_port = htons(port);
+
+ if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
+ pr_perror("Unable to connect to remote %s", hostname);
+ goto err;
+ }
+
+ return sockfd;
+err:
+ close(sockfd);
+ return -1;
+}
+
int image_proxy(bool background, char *local_proxy_path, char *fwd_host, unsigned short fwd_port)
{
pr_info("CRIU to Proxy Path: %s, Cache Address %s:%hu\n",
diff --git a/criu/img-remote.c b/criu/img-remote.c
index 4593f41f..51fa0337 100644
--- a/criu/img-remote.c
+++ b/criu/img-remote.c
@@ -5,7 +5,6 @@
#include <sys/socket.h>
#include <sys/epoll.h>
#include <netinet/in.h>
-#include <netdb.h>
#include "xmalloc.h"
#include "criu-log.h"
#include "img-remote.h"
@@ -120,42 +119,6 @@ struct roperation *get_rop_by_name(
return NULL;
}
-int setup_TCP_client_socket(char *hostname, int port)
-{
- int sockfd;
- struct sockaddr_in serv_addr;
- struct hostent *server;
-
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0) {
- pr_perror("Unable to open remote image socket");
- return -1;
- }
-
- server = gethostbyname(hostname);
- if (server == NULL) {
- pr_perror("Unable to get host by name (%s)", hostname);
- goto err;
- }
-
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- bcopy((char *) server->h_addr,
- (char *) &serv_addr.sin_addr.s_addr,
- server->h_length);
- serv_addr.sin_port = htons(port);
-
- if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
- pr_perror("Unable to connect to remote %s", hostname);
- goto err;
- }
-
- return sockfd;
-err:
- close(sockfd);
- return -1;
-}
-
int event_set(int epoll_fd, int op, int fd, uint32_t events, void *data)
{
int ret;
diff --git a/criu/include/img-remote.h b/criu/include/img-remote.h
index ac17025d..62ea5c9d 100644
--- a/criu/include/img-remote.h
+++ b/criu/include/img-remote.h
@@ -85,7 +85,6 @@ int64_t recv_image_async(struct roperation *op);
int64_t read_remote_header(int fd, char *snapshot_id, char *path, int *open_mode, uint64_t *size);
int64_t write_remote_header(int fd, char *snapshot_id, char *path, int open_mode, uint64_t size);
-int setup_TCP_client_socket(char *hostname, int port);
int setup_UNIX_server_socket(char *path);
void socket_set_non_blocking(int fd);
--
2.17.1
More information about the CRIU
mailing list