Explorar o código

Reduce code by using incomplete struct types

Oleh Kulykov %!s(int64=8) %!d(string=hai) anos
pai
achega
c04be3f45c

+ 3 - 3
librws.h

@@ -104,13 +104,13 @@ typedef void* rws_handle;
 /**
  @brief Socket handle.
  */
-typedef rws_handle rws_socket;
+typedef struct rws_socket_struct * rws_socket;
 
 
 /**
  @brief Error object handle.
  */
-typedef rws_handle rws_error;
+typedef struct rws_error_struct * rws_error;
 
 
 /**
@@ -122,7 +122,7 @@ typedef rws_handle rws_mutex;
 /**
  @brief Thread object handle.
  */
-typedef rws_handle rws_thread;
+typedef struct rws_thread_struct * rws_thread;
 
 
 /**

+ 9 - 12
src/rws_error.c

@@ -28,25 +28,25 @@
 
 
 // private
-_rws_error * rws_error_create(void) {
-	return (_rws_error *)rws_malloc_zero(sizeof(_rws_error));
+rws_error rws_error_create(void) {
+	return (rws_error)rws_malloc_zero(sizeof(struct rws_error_struct));
 }
 
-_rws_error * rws_error_new_code_descr(const int code, const char * description) {
-	_rws_error * e = (_rws_error *)rws_malloc_zero(sizeof(_rws_error));
+rws_error rws_error_new_code_descr(const int code, const char * description) {
+	rws_error e = (rws_error)rws_malloc_zero(sizeof(struct rws_error_struct));
 	e->code = code;
 	e->description = rws_string_copy(description);
 	return e;
 }
 
-void rws_error_delete(_rws_error * error) {
+void rws_error_delete(rws_error error) {
 	if (error) {
 		rws_string_delete(error->description);
 		rws_free(error);
 	}
 }
 
-void rws_error_delete_clean(_rws_error ** error) {
+void rws_error_delete_clean(rws_error * error) {
 	if (error) {
 		rws_error_delete(*error);
 		*error = NULL;
@@ -55,17 +55,14 @@ void rws_error_delete_clean(_rws_error ** error) {
 
 // public
 int rws_error_get_code(rws_error error) {
-	_rws_error * e = (_rws_error *)error;
-	return e ? e->code : 0;
+	return error ? error->code : 0;
 }
 
 int rws_error_get_http_error(rws_error error) {
-	_rws_error * e = (_rws_error *)error;
-	return e ? e->http_error : 0;
+	return error ? error->http_error : 0;
 }
 
 const char * rws_error_get_description(rws_error error) {
-	_rws_error * e = (_rws_error *)error;
-	return e ? e->description : NULL;
+	return error ? error->description : NULL;
 }
 

+ 6 - 6
src/rws_error.h

@@ -26,18 +26,18 @@
 
 #include "rws_string.h"
 
-typedef struct _rws_error_struct {
+struct rws_error_struct {
 	int code;
 	int http_error;
 	char * description;
-} _rws_error;
+};
 
-_rws_error * rws_error_create(void);
+rws_error rws_error_create(void);
 
-_rws_error * rws_error_new_code_descr(const int code, const char * description);
+rws_error rws_error_new_code_descr(const int code, const char * description);
 
-void rws_error_delete(_rws_error * error);
+void rws_error_delete(rws_error error);
 
-void rws_error_delete_clean(_rws_error ** error);
+void rws_error_delete_clean(rws_error * error);
 
 #endif

+ 1 - 1
src/rws_frame.c

@@ -217,7 +217,7 @@ void rws_frame_delete_clean(_rws_frame ** f) {
 	}
 }
 
-size_t rws_check_recv_frame_size( const void *data ,const size_t data_size) {
+size_t rws_check_recv_frame_size(const void * data, const size_t data_size) {
 	if (data && data_size >= 2) {
 		const unsigned char * udata = (const unsigned char *)data;
 		//        const unsigned int is_finshd = (udata[0] >> 7) & 0x01;

+ 1 - 1
src/rws_frame.h

@@ -46,7 +46,7 @@ typedef struct _rws_frame_struct {
 	unsigned char header_size;
 } _rws_frame;
 
-size_t rws_check_recv_frame_size(const void *data,const size_t data_size);
+size_t rws_check_recv_frame_size(const void * data, const size_t data_size);
 
 _rws_frame * rws_frame_create_with_recv_data(const void * data, const size_t data_size);
 

+ 29 - 29
src/rws_socket.h

@@ -59,7 +59,7 @@ typedef int rws_socket_t;
 static const char * k_rws_socket_min_http_ver = "1.1";
 static const char * k_rws_socket_sec_websocket_accept = "Sec-WebSocket-Accept";
 
-typedef struct _rws_socket_struct {
+struct rws_socket_struct {
 	int port;
 	rws_socket_t socket;
 	char * scheme;
@@ -89,69 +89,69 @@ typedef struct _rws_socket_struct {
 	_rws_list * send_frames;
 	_rws_list * recvd_frames;
 
-	_rws_error * error;
+	rws_error error;
 
 	rws_mutex work_mutex;
 	rws_mutex send_mutex;
-} _rws_socket;
+};
 
-rws_bool rws_socket_process_handshake_responce(_rws_socket * s);
+rws_bool rws_socket_process_handshake_responce(rws_socket s);
 
 // receive raw data from socket
-rws_bool rws_socket_recv(_rws_socket * s);
+rws_bool rws_socket_recv(rws_socket s);
 
 // send raw data to socket
-rws_bool rws_socket_send(_rws_socket * s, const void * data, const size_t data_size);
+rws_bool rws_socket_send(rws_socket s, const void * data, const size_t data_size);
 
-_rws_frame * rws_socket_last_unfin_recvd_frame_by_opcode(_rws_socket * s, const rws_opcode opcode);
+_rws_frame * rws_socket_last_unfin_recvd_frame_by_opcode(rws_socket s, const rws_opcode opcode);
 
-void rws_socket_process_bin_or_text_frame(_rws_socket * s, _rws_frame * frame);
+void rws_socket_process_bin_or_text_frame(rws_socket s, _rws_frame * frame);
 
-void rws_socket_process_ping_frame(_rws_socket * s, _rws_frame * frame);
+void rws_socket_process_ping_frame(rws_socket s, _rws_frame * frame);
 
-void rws_socket_process_conn_close_frame(_rws_socket * s, _rws_frame * frame);
+void rws_socket_process_conn_close_frame(rws_socket s, _rws_frame * frame);
 
-void rws_socket_process_received_frame(_rws_socket * s, _rws_frame * frame);
+void rws_socket_process_received_frame(rws_socket s, _rws_frame * frame);
 
-void rws_socket_idle_recv(_rws_socket * s);
+void rws_socket_idle_recv(rws_socket s);
 
-void rws_socket_idle_send(_rws_socket * s);
+void rws_socket_idle_send(rws_socket s);
 
-void rws_socket_wait_handshake_responce(_rws_socket * s);
+void rws_socket_wait_handshake_responce(rws_socket s);
 
-unsigned int rws_socket_get_next_message_id(_rws_socket * s);
+unsigned int rws_socket_get_next_message_id(rws_socket s);
 
-void rws_socket_send_ping(_rws_socket * s);
+void rws_socket_send_ping(rws_socket s);
 
-void rws_socket_send_disconnect(_rws_socket * s);
+void rws_socket_send_disconnect(rws_socket s);
 
-void rws_socket_send_handshake(_rws_socket * s);
+void rws_socket_send_handshake(rws_socket s);
 
-struct addrinfo * rws_socket_connect_getaddr_info(_rws_socket * s);
+struct addrinfo * rws_socket_connect_getaddr_info(rws_socket s);
 
-void rws_socket_connect_to_host(_rws_socket * s);
+void rws_socket_connect_to_host(rws_socket s);
 
-rws_bool rws_socket_create_start_work_thread(_rws_socket * s);
+rws_bool rws_socket_create_start_work_thread(rws_socket s);
 
-void rws_socket_close(_rws_socket * s);
+void rws_socket_close(rws_socket s);
 
-void rws_socket_resize_received(_rws_socket * s, const size_t size);
+void rws_socket_resize_received(rws_socket s, const size_t size);
 
-void rws_socket_append_recvd_frames(_rws_socket * s, _rws_frame * frame);
+void rws_socket_append_recvd_frames(rws_socket s, _rws_frame * frame);
 
-void rws_socket_append_send_frames(_rws_socket * s, _rws_frame * frame);
+void rws_socket_append_send_frames(rws_socket s, _rws_frame * frame);
 
-rws_bool rws_socket_send_text_priv(_rws_socket * s, const char * text);
+rws_bool rws_socket_send_text_priv(rws_socket s, const char * text);
 
-void rws_socket_inform_recvd_frames(_rws_socket * s);
+void rws_socket_inform_recvd_frames(rws_socket s);
 
 void rws_socket_set_option(rws_socket_t s, int option, int value);
 
 void rws_socket_delete_all_frames_in_list(_rws_list * list_with_frames);
 
-void rws_socket_check_write_error(_rws_socket * s, int error_num);
+void rws_socket_check_write_error(rws_socket s, int error_num);
 
-void rws_socket_delete(_rws_socket * s);
+void rws_socket_delete(rws_socket s);
 
 #define COMMAND_IDLE -1
 #define COMMAND_NONE 0

+ 26 - 26
src/rws_socketpriv.c

@@ -34,7 +34,7 @@
 #define	WSAEINPROGRESS     EINPROGRESS	
 #endif
 
-unsigned int rws_socket_get_next_message_id(_rws_socket * s) {
+unsigned int rws_socket_get_next_message_id(rws_socket s) {
 	const unsigned int mess_id = ++s->next_message_id;
 	if (mess_id > 9999999) {
 		s->next_message_id = 0;
@@ -42,7 +42,7 @@ unsigned int rws_socket_get_next_message_id(_rws_socket * s) {
 	return mess_id;
 }
 
-void rws_socket_send_ping(_rws_socket * s) {
+void rws_socket_send_ping(rws_socket s) {
 	char buff[16];
 	size_t len = 0;
 	_rws_frame * frame = rws_frame_create();
@@ -55,7 +55,7 @@ void rws_socket_send_ping(_rws_socket * s) {
 	rws_socket_append_send_frames(s, frame);
 }
 
-void rws_socket_inform_recvd_frames(_rws_socket * s) {
+void rws_socket_inform_recvd_frames(rws_socket s) {
 	rws_bool is_all_finished = rws_true;
 	_rws_frame * frame = NULL;
 	_rws_node * cur = s->recvd_frames;
@@ -106,7 +106,7 @@ void rws_socket_read_handshake_responce_value(const char * str, char ** value) {
 	}
 }
 
-rws_bool rws_socket_process_handshake_responce(_rws_socket * s) {
+rws_bool rws_socket_process_handshake_responce(rws_socket s) {
 	const char * str = (const char *)s->received;
 	const char * sub = NULL;
 	float http_ver = -1;
@@ -139,7 +139,7 @@ rws_bool rws_socket_process_handshake_responce(_rws_socket * s) {
 }
 
 // need close socket on error
-rws_bool rws_socket_send(_rws_socket * s, const void * data, const size_t data_size) {
+rws_bool rws_socket_send(rws_socket s, const void * data, const size_t data_size) {
 	int sended = -1, error_number = -1;
 	rws_error_delete_clean(&s->error);
 
@@ -165,7 +165,7 @@ rws_bool rws_socket_send(_rws_socket * s, const void * data, const size_t data_s
 	return rws_true;
 }
 
-rws_bool rws_socket_recv(_rws_socket * s) {
+rws_bool rws_socket_recv(rws_socket s) {
 	int is_reading = 1, error_number = -1, len = -1;
 	char * received = NULL;
 	size_t total_len = 0;
@@ -202,7 +202,7 @@ rws_bool rws_socket_recv(_rws_socket * s) {
 	return rws_true;
 }
 
-_rws_frame * rws_socket_last_unfin_recvd_frame_by_opcode(_rws_socket * s, const rws_opcode opcode) {
+_rws_frame * rws_socket_last_unfin_recvd_frame_by_opcode(rws_socket s, const rws_opcode opcode) {
 	_rws_frame * last = NULL;
 	_rws_frame * frame = NULL;
 	_rws_node * cur = s->recvd_frames;
@@ -219,7 +219,7 @@ _rws_frame * rws_socket_last_unfin_recvd_frame_by_opcode(_rws_socket * s, const
 	return last;
 }
 
-void rws_socket_process_bin_or_text_frame(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_process_bin_or_text_frame(rws_socket s, _rws_frame * frame) {
 	_rws_frame * last_unfin = rws_socket_last_unfin_recvd_frame_by_opcode(s, frame->opcode);
 	if (last_unfin) {
 		rws_frame_combine_datas(last_unfin, frame);
@@ -232,7 +232,7 @@ void rws_socket_process_bin_or_text_frame(_rws_socket * s, _rws_frame * frame) {
 	}
 }
 
-void rws_socket_process_ping_frame(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_process_ping_frame(rws_socket s, _rws_frame * frame) {
 	_rws_frame * pong_frame = rws_frame_create();
 	pong_frame->opcode = rws_opcode_pong;
 	pong_frame->is_masked = rws_true;
@@ -241,14 +241,14 @@ void rws_socket_process_ping_frame(_rws_socket * s, _rws_frame * frame) {
 	rws_socket_append_send_frames(s, pong_frame);
 }
 
-void rws_socket_process_conn_close_frame(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_process_conn_close_frame(rws_socket s, _rws_frame * frame) {
 	s->command = COMMAND_INFORM_DISCONNECTED;
 	s->error = rws_error_new_code_descr(rws_error_code_connection_closed, "Connection was closed by endpoint");
 	//rws_socket_close(s);
 	rws_frame_delete(frame);
 }
 
-void rws_socket_process_received_frame(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_process_received_frame(rws_socket s, _rws_frame * frame) {
 	switch (frame->opcode) {
 		case rws_opcode_ping: rws_socket_process_ping_frame(s, frame); break;
 		case rws_opcode_text_frame:
@@ -264,7 +264,7 @@ void rws_socket_process_received_frame(_rws_socket * s, _rws_frame * frame) {
 	}
 }
 
-void rws_socket_idle_recv(_rws_socket * s) {
+void rws_socket_idle_recv(rws_socket s) {
 	_rws_frame * frame = NULL;
 
 	if (!rws_socket_recv(s)) {
@@ -292,7 +292,7 @@ void rws_socket_idle_recv(_rws_socket * s) {
    }
 }
 
-void rws_socket_idle_send(_rws_socket * s) {
+void rws_socket_idle_send(rws_socket s) {
 	_rws_node * cur = NULL;
 	rws_bool sending = rws_true;
 	_rws_frame * frame = NULL;
@@ -317,7 +317,7 @@ void rws_socket_idle_send(_rws_socket * s) {
 	rws_mutex_unlock(s->send_mutex);
 }
 
-void rws_socket_wait_handshake_responce(_rws_socket * s) {
+void rws_socket_wait_handshake_responce(rws_socket s) {
 	if (!rws_socket_recv(s)) {
 		// sock already closed
 		if (s->error) {
@@ -340,7 +340,7 @@ void rws_socket_wait_handshake_responce(_rws_socket * s) {
 	}
 }
 
-void rws_socket_send_disconnect(_rws_socket * s) {
+void rws_socket_send_disconnect(rws_socket s) {
 	char buff[16];
 	size_t len = 0;
 	_rws_frame * frame = rws_frame_create();
@@ -356,7 +356,7 @@ void rws_socket_send_disconnect(_rws_socket * s) {
 	rws_thread_sleep(RWS_CONNECT_RETRY_DELAY); // little bit wait after send message
 }
 
-void rws_socket_send_handshake(_rws_socket * s) {
+void rws_socket_send_handshake(rws_socket s) {
 	char buff[512];
 	char * ptr = buff;
 	size_t writed = 0;
@@ -394,7 +394,7 @@ void rws_socket_send_handshake(_rws_socket * s) {
 	}
 }
 
-struct addrinfo * rws_socket_connect_getaddr_info(_rws_socket * s) {
+struct addrinfo * rws_socket_connect_getaddr_info(rws_socket s) {
 	struct addrinfo hints;
 	char portstr[16];
 	struct addrinfo * result = NULL;
@@ -447,7 +447,7 @@ struct addrinfo * rws_socket_connect_getaddr_info(_rws_socket * s) {
 	return NULL;
 }
 
-void rws_socket_connect_to_host(_rws_socket * s) {
+void rws_socket_connect_to_host(rws_socket s) {
 	struct addrinfo * result = NULL;
 	struct addrinfo * p = NULL;
 	rws_socket_t sock = RWS_INVALID_SOCKET;
@@ -502,7 +502,7 @@ void rws_socket_connect_to_host(_rws_socket * s) {
 }
 
 static void rws_socket_work_th_func(void * user_object) {
-	_rws_socket * s = (_rws_socket *)user_object;
+	rws_socket s = (rws_socket)user_object;
 	size_t loop_number = 0;
 	while (s->command < COMMAND_END) {
 		loop_number++;
@@ -564,7 +564,7 @@ static void rws_socket_work_th_func(void * user_object) {
 	rws_socket_delete(s);
 }
 
-rws_bool rws_socket_create_start_work_thread(_rws_socket * s) {
+rws_bool rws_socket_create_start_work_thread(rws_socket s) {
 	rws_error_delete_clean(&s->error);
 	s->command = COMMAND_NONE;
 	s->work_thread = rws_thread_create(&rws_socket_work_th_func, s);
@@ -575,7 +575,7 @@ rws_bool rws_socket_create_start_work_thread(_rws_socket * s) {
 	return rws_false;
 }
 
-void rws_socket_resize_received(_rws_socket * s, const size_t size) {
+void rws_socket_resize_received(rws_socket s, const size_t size) {
 	void * res = NULL;
 	size_t min = 0;
 	if (size == s->received_size) {
@@ -594,7 +594,7 @@ void rws_socket_resize_received(_rws_socket * s, const size_t size) {
 	s->received_size = size;
 }
 
-void rws_socket_close(_rws_socket * s) {
+void rws_socket_close(rws_socket s) {
     s->received_len = 0;
 	if (s->socket != RWS_INVALID_SOCKET) {
 		RWS_SOCK_CLOSE(s->socket);
@@ -606,7 +606,7 @@ void rws_socket_close(_rws_socket * s) {
 	s->is_connected = rws_false;
 }
 
-void rws_socket_append_recvd_frames(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_append_recvd_frames(rws_socket s, _rws_frame * frame) {
 	_rws_node_value frame_list_var;
 	frame_list_var.object = frame;
 	if (s->recvd_frames) {
@@ -617,7 +617,7 @@ void rws_socket_append_recvd_frames(_rws_socket * s, _rws_frame * frame) {
 	}
 }
 
-void rws_socket_append_send_frames(_rws_socket * s, _rws_frame * frame) {
+void rws_socket_append_send_frames(rws_socket s, _rws_frame * frame) {
 	_rws_node_value frame_list_var;
 	frame_list_var.object = frame;
 	if (s->send_frames) {
@@ -628,7 +628,7 @@ void rws_socket_append_send_frames(_rws_socket * s, _rws_frame * frame) {
 	}
 }
 
-rws_bool rws_socket_send_text_priv(_rws_socket * s, const char * text) {
+rws_bool rws_socket_send_text_priv(rws_socket s, const char * text) {
 	size_t len = text ? strlen(text) : 0;
 	_rws_frame * frame = NULL;
 
@@ -661,7 +661,7 @@ void rws_socket_set_option(rws_socket_t s, int option, int value) {
 	setsockopt(s, SOL_SOCKET, option, (char *)&value, sizeof(int));
 }
 
-void rws_socket_check_write_error(_rws_socket * s, int error_num) {
+void rws_socket_check_write_error(rws_socket s, int error_num) {
 #if defined(RWS_OS_WINDOWS)
 	int socket_code = 0, code = 0;
 	unsigned int socket_code_size = sizeof(int);

+ 70 - 90
src/rws_socketpub.c

@@ -33,68 +33,65 @@
 
 // public
 rws_bool rws_socket_connect(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
 	const char * params_error_msg = NULL;
-	if (!s) {
+	if (!socket) {
 		return rws_false;
 	}
 
-	rws_error_delete_clean(&s->error);
+	rws_error_delete_clean(&socket->error);
 
-	if (s->port <= 0) {
+	if (socket->port <= 0) {
 		params_error_msg = "No URL port provided";
 	}
-	if (!s->scheme) {
+	if (!socket->scheme) {
 		params_error_msg = "No URL scheme provided";
 	}
-	if (!s->host) {
+	if (!socket->host) {
 		params_error_msg = "No URL host provided";
 	}
-	if (!s->path) {
+	if (!socket->path) {
 		params_error_msg = "No URL path provided";
 	}
-	if (!s->on_disconnected) {
+	if (!socket->on_disconnected) {
 		params_error_msg = "No on_disconnected callback provided";
 	}
-    s->received_len = 0;
+    socket->received_len = 0;
 	if (params_error_msg) {
-		s->error = rws_error_new_code_descr(rws_error_code_missed_parameter, params_error_msg);
+		socket->error = rws_error_new_code_descr(rws_error_code_missed_parameter, params_error_msg);
 		return rws_false;
 	}
-	return rws_socket_create_start_work_thread(s);
+	return rws_socket_create_start_work_thread(socket);
 }
 
 void rws_socket_disconnect_and_release(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (!s) {
+	if (!socket) {
 		return;
 	}
 	
-	rws_mutex_lock(s->work_mutex);
-
-	rws_socket_delete_all_frames_in_list(s->send_frames);
-	rws_list_delete_clean(&s->send_frames);
-
-	if (s->is_connected) { // connected in loop
-		s->command = COMMAND_DISCONNECT;
-		rws_mutex_unlock(s->work_mutex);
-	} else if (s->work_thread) { // disconnected in loop
-		s->command = COMMAND_END;
-		rws_mutex_unlock(s->work_mutex);
-	} else if (s->command != COMMAND_END) {
+	rws_mutex_lock(socket->work_mutex);
+
+	rws_socket_delete_all_frames_in_list(socket->send_frames);
+	rws_list_delete_clean(&socket->send_frames);
+
+	if (socket->is_connected) { // connected in loop
+		socket->command = COMMAND_DISCONNECT;
+		rws_mutex_unlock(socket->work_mutex);
+	} else if (socket->work_thread) { // disconnected in loop
+		socket->command = COMMAND_END;
+		rws_mutex_unlock(socket->work_mutex);
+	} else if (socket->command != COMMAND_END) {
 		// not in loop
-		rws_mutex_unlock(s->work_mutex);
-		rws_socket_delete(s);
+		rws_mutex_unlock(socket->work_mutex);
+		rws_socket_delete(socket);
 	}
 }
 
 rws_bool rws_socket_send_text(rws_socket socket, const char * text) {
-	_rws_socket * s = (_rws_socket *)socket;
 	rws_bool r = rws_false;
-	if (s) {
-		rws_mutex_lock(s->send_mutex);
-		r = rws_socket_send_text_priv(s, text);
-		rws_mutex_unlock(s->send_mutex);
+	if (socket) {
+		rws_mutex_lock(socket->send_mutex);
+		r = rws_socket_send_text_priv(socket, text);
+		rws_mutex_unlock(socket->send_mutex);
 	}
 	return r;
 }
@@ -116,7 +113,7 @@ void rws_socket_check_info(const char * info) {
 }
 
 rws_socket rws_socket_create(void) {
-	_rws_socket * s = (_rws_socket *)rws_malloc_zero(sizeof(_rws_socket));
+	rws_socket s = (rws_socket)rws_malloc_zero(sizeof(struct rws_socket_struct));
 	if (!s) {
 		return NULL;
 	}
@@ -138,7 +135,7 @@ rws_socket rws_socket_create(void) {
 	return s;
 }
 
-void rws_socket_delete(_rws_socket * s) {
+void rws_socket_delete(rws_socket s) {
 	rws_socket_close(s);
 
 	rws_string_delete_clean(&s->sec_ws_accept);
@@ -177,70 +174,61 @@ void rws_socket_set_url(rws_socket socket,
 						const char * host,
 						const int port,
 						const char * path) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		rws_string_delete(s->scheme);
-		s->scheme = rws_string_copy(scheme);
+	if (socket) {
+		rws_string_delete(socket->scheme);
+		socket->scheme = rws_string_copy(scheme);
 		
-		rws_string_delete(s->host);
-		s->host = rws_string_copy(host);
+		rws_string_delete(socket->host);
+		socket->host = rws_string_copy(host);
 		
-		rws_string_delete(s->path);
-		s->path = rws_string_copy(path);
+		rws_string_delete(socket->path);
+		socket->path = rws_string_copy(path);
 		
-		s->port = port;
+		socket->port = port;
 	}
 }
 
 void rws_socket_set_scheme(rws_socket socket, const char * scheme) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		rws_string_delete(s->scheme);
-		s->scheme = rws_string_copy(scheme);
+	if (socket) {
+		rws_string_delete(socket->scheme);
+		socket->scheme = rws_string_copy(scheme);
 	}
 }
 
 const char * rws_socket_get_scheme(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->scheme : NULL;
+	return socket ? socket->scheme : NULL;
 }
 
 void rws_socket_set_host(rws_socket socket, const char * host) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		rws_string_delete(s->host);
-		s->host = rws_string_copy(host);
+	if (socket) {
+		rws_string_delete(socket->host);
+		socket->host = rws_string_copy(host);
 	}
 }
 
 const char * rws_socket_get_host(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->host : NULL;
+	return socket ? socket->host : NULL;
 }
 
 void rws_socket_set_path(rws_socket socket, const char * path) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		rws_string_delete(s->path);
-		s->path = rws_string_copy(path);
+	if (socket) {
+		rws_string_delete(socket->path);
+		socket->path = rws_string_copy(path);
 	}
 }
 
 const char * rws_socket_get_path(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->path : NULL;
+	return socket ? socket->path : NULL;
 }
 
 void rws_socket_set_port(rws_socket socket, const int port) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->port = port;
+	if (socket) {
+		socket->port = port;
 	}
 }
 
 int rws_socket_get_port(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->port : -1;
+	return socket ? socket->port : -1;
 }
 
 /*
@@ -273,57 +261,49 @@ unsigned int rws_socket_get_receive_buffer_size(rws_socket socket) {
 */
 
 rws_error rws_socket_get_error(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->error : NULL;
+	return socket ? socket->error : NULL;
 }
 
 void rws_socket_set_user_object(rws_socket socket, void * user_object) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->user_object = user_object;
+	if (socket) {
+		socket->user_object = user_object;
 	}
 }
 
 void * rws_socket_get_user_object(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
-	return s ? s->user_object : NULL;
+	return socket ? socket->user_object : NULL;
 }
 
 void rws_socket_set_on_connected(rws_socket socket, rws_on_socket callback) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->on_connected = callback;
+	if (socket) {
+		socket->on_connected = callback;
 	}
 }
 
 void rws_socket_set_on_disconnected(rws_socket socket, rws_on_socket callback) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->on_disconnected = callback;
+	if (socket) {
+		socket->on_disconnected = callback;
 	}
 }
 
 void rws_socket_set_on_received_text(rws_socket socket, rws_on_socket_recvd_text callback) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->on_recvd_text = callback;
+	if (socket) {
+		socket->on_recvd_text = callback;
 	}
 }
 
 void rws_socket_set_on_received_bin(rws_socket socket, rws_on_socket_recvd_bin callback) {
-	_rws_socket * s = (_rws_socket *)socket;
-	if (s) {
-		s->on_recvd_bin = callback;
+	if (socket) {
+		socket->on_recvd_bin = callback;
 	}
 }
 
 rws_bool rws_socket_is_connected(rws_socket socket) {
-	_rws_socket * s = (_rws_socket *)socket;
 	rws_bool r = rws_false;
-	if (s) {
-		rws_mutex_lock(s->send_mutex);
-		r = s->is_connected;
-		rws_mutex_unlock(s->send_mutex);
+	if (socket) {
+		rws_mutex_lock(socket->send_mutex);
+		r = socket->is_connected;
+		rws_mutex_unlock(socket->send_mutex);
 	}
 	return r;
 }

+ 8 - 8
src/rws_thread.c

@@ -35,7 +35,7 @@
 #include <unistd.h>
 #endif
 
-typedef struct _rws_thread_struct {
+struct rws_thread_struct {
 	rws_thread_funct thread_function;
 	void * user_object;
 #if defined(RWS_OS_WINDOWS)
@@ -43,16 +43,16 @@ typedef struct _rws_thread_struct {
 #else
 	pthread_t thread;
 #endif
-} _rws_thread;
+};
 
 typedef struct _rws_threads_joiner_struct {
-	_rws_thread * thread;
+	rws_thread thread;
 	rws_mutex mutex;
 } _rws_threads_joiner;
 
 static _rws_threads_joiner * _threads_joiner = NULL;
 static void rws_threads_joiner_clean(void) { // private
-	_rws_thread * t = _threads_joiner->thread;
+	rws_thread t = _threads_joiner->thread;
 #if defined(RWS_OS_WINDOWS)
 	DWORD dwExitCode = 0;
 #else
@@ -83,7 +83,7 @@ static void rws_threads_joiner_clean(void) { // private
 	rws_free(t);
 }
 
-static void rws_threads_joiner_add(_rws_thread * thread) { // public
+static void rws_threads_joiner_add(rws_thread thread) { // public
 	rws_mutex_lock(_threads_joiner->mutex);
 	rws_threads_joiner_clean();
 	_threads_joiner->thread = thread;
@@ -103,7 +103,7 @@ static DWORD WINAPI rws_thread_func_priv(LPVOID some_pointer) {
 #else
 static void * rws_thread_func_priv(void * some_pointer) {
 #endif
-	_rws_thread * t = (_rws_thread *)some_pointer;
+	rws_thread t = (rws_thread)some_pointer;
 	t->thread_function(t->user_object);
 	rws_threads_joiner_add(t);
 
@@ -115,7 +115,7 @@ static void * rws_thread_func_priv(void * some_pointer) {
 }
 
 rws_thread rws_thread_create(rws_thread_funct thread_function, void * user_object) {
-	_rws_thread * t = NULL;
+	rws_thread t = NULL;
 	int res = -1;
 #if !defined(RWS_OS_WINDOWS)
 	pthread_attr_t attr;
@@ -125,7 +125,7 @@ rws_thread rws_thread_create(rws_thread_funct thread_function, void * user_objec
 		return NULL;
 	}
 	rws_threads_joiner_create_ifneed();
-	t = (_rws_thread *)rws_malloc_zero(sizeof(_rws_thread));
+	t = (rws_thread)rws_malloc_zero(sizeof(struct rws_thread_struct));
 	t->user_object = user_object;
 	t->thread_function = thread_function;
 #if defined(RWS_OS_WINDOWS)

BIN=BIN
test/librws_test.xcodeproj/project.xcworkspace/xcuserdata/olehkulykov.xcuserdatad/UserInterfaceState.xcuserstate


+ 1 - 1
test/librws_testTests/connection.m

@@ -26,7 +26,7 @@
 
 @interface connection : XCTestCase {
 @private
-	rws_socket * _socket;
+	rws_socket _socket;
 }
 
 @property (nonatomic) BOOL isWorking;

+ 1 - 1
test/librws_testTests/creation.m

@@ -44,7 +44,7 @@
 {
     // This is an example of a functional test case.
     // Use XCTAssert and related functions to verify your tests produce the correct results.
-	rws_socket * socket = rws_socket_create();
+	rws_socket socket = rws_socket_create();
 	XCTAssert(socket != NULL, @"Not created");
 	rws_socket_disconnect_and_release(socket);
 

+ 1 - 1
test/librws_testTests/getterAndSetters.m

@@ -26,7 +26,7 @@
 
 @interface getterAndSetters : XCTestCase {
 @private
-	rws_socket * _socket;
+	rws_socket _socket;
 }
 @end